Choose a setup method
Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.
Recommended: Agnost AI skill
Recommended. Choose this path when you want your coding agent to inspect the
project, select a supported transport, make the smallest instrumentation change,
send a test event, and verify that it reached Agnost AI.
Manual setup: Agnost AI SDK
agnost.shutdown() once when the application exits, not after each request.
Shutting down per request disables telemetry for later agent runs in the same process.
Manual setup: OpenTelemetry
The OpenInference Haystack instrumentation emits a span for every pipeline run, component run,Agent.run(), and chat generator call. Send those spans to Agnost AI over OTLP, and wrap each turn in one short span that carries the user’s message and the agent’s answer.
Haystack also has its own tracer (
OpenTelemetryTracer from the opentelemetry-haystack package). Its spans only carry haystack.* attributes, with no model, message, or token attributes in a standard format, so Agnost AI does not ingest them. Use OpenInference.1. Install
haystack-ai 3.5.0, anthropic-haystack 8.2.0, anthropic 2.14.0, openinference-instrumentation-haystack 0.1.56, and opentelemetry-sdk 1.45.2 on Python 3.12.
2. Point OpenTelemetry at Agnost AI and run an agent
HaystackInstrumentor().instrument()tracesPipeline.run(), every component’srun(),Agent.run(), and chat generators such asAnthropicChatGenerator.using_attributes(user_id=..., session_id=...)writesuser.idandsession.idonto every span Haystack emits inside the block. Every turn with the samesession_idlands in the same Agnost AI conversation.- The
agent_turnspan becomes the root of each trace. Agnost AI builds the conversation transcript from each trace’s root span. The root span OpenInference writes forAgent.run()holds serializedChatMessageobjects, so the wrapper puts the plain user message and the final answer there instead. ANTHROPIC_OPEN_TELEMETRY=falsestops theanthropicSDK from adding a second, metadata-onlychatspan under every generator call. Leave it unset if you want those spans too.
Pipeline: call pipeline.run(...) inside run_turn and read the answer from the pipeline’s output.
In a long-running server, create the TracerProvider and call instrument() once at startup, call run_turn per request, and call provider.shutdown() on graceful shutdown.
What appears in Agnost AI
- Conversations: one per
session_id. Agnost AI keeps the raw session ID asoriginal_conversation_idin the conversation metadata. - Users: the
user_idyou pass tousing_attributes. - Messages: the user’s message and the agent’s answer for each turn, from the
agent_turnspan. - Events: the turn (
agent),Agent.run(chain),ChatPromptBuilder.run(chain), and oneAnthropicChatGenerator.run(llm) per model call, with the model name, input and output messages, and token counts.
Agent runs its tools directly, not through a ToolInvoker component, so tool calls do not get their own event. Each tool call and its result are visible in the input and output messages of the model call around it.
Verify
Run the script, wait up to a minute for ingestion, then open Conversations in Agnost AI. Confirm the conversation shows youruser_id, a user message and an assistant answer, and two AnthropicChatGenerator.run events: one that asks for get_order_status, and one that answers with its result.
Troubleshooting
- Nothing arrives: confirm the exporter’s headers contain
X-Agnost-Org-ID, and that the script callsprovider.shutdown()orprovider.force_flush()before it exits.BatchSpanProcessorexports in the background. - Only
haystack.*spans in your own collector, nothing in Agnost AI: you enabled Haystack’sOpenTelemetryTracerinstead of OpenInference. Agnost AI drops those spans. - The user message is a JSON blob of
ChatMessage(...)objects: the turn ran outside theagent_turnspan. Callagent.run()insiderun_turn. - User or conversation is missing: call
agent.run()inside theusing_attributesblock. - Each model call appears twice: set
ANTHROPIC_OPEN_TELEMETRY=falsebefore the generator is created.
References
- OpenInference Haystack instrumentation
- Haystack tracing
- Haystack Arize Phoenix integration
- Haystack Anthropic integration
Next steps
- Conversations: review the complete Haystack session.
- Events: inspect agent, component, and model activity.
- Patterns: organize production conversations by what users wanted.