query() function for one-off tasks or the ClaudeSDKClient class for multi-turn conversations. Once an agent reaches production, you need to see what it does on every run: which tools it calls, in what order, with what inputs, and how many tokens each turn costs.
Add Arize AX tracing to an agent you have already built with the Claude Agent SDK. You attach the OpenInference instrumentor for the SDK once, in Python or TypeScript, and every agent run and tool call is captured as a structured trace without changing your agent logic.
If your agent is built directly on the Anthropic SDK (a Messages API tool loop) rather than the Claude Agent SDK, see Agents Built with the Anthropic SDK instead. That path captures model calls automatically and has you add manual spans for the loop and tools.
Overview
You will instrument an existing Claude Agent SDK application, run it, and read the resulting traces in Arize AX. The steps apply to any app built on the SDK, whether it runs as a script, a worker, or behind a web framework such as FastAPI or Express. Intended for developers who have a working Claude Agent SDK agent and want production observability for it. It assumes you are comfortable with:- Python or TypeScript, including
async/awaitand async iteration - The Claude Agent SDK
query()entry point (andClaudeSDKClientfor multi-turn work) - Environment variables and package installation
- Initialize Arize AX tracing so the SDK is instrumented before it runs
- Capture agent runs and tool calls as traces with no changes to your agent logic
- Group traces by conversation using session IDs
- Verify and read the trace tree in Arize AX
Before you start
You need:- An existing agent built with the Claude Agent SDK
- An Arize AX account (sign up)
- An
ANTHROPIC_API_KEYfrom the Claude Console
Get your Arize AX credentials
Sign in to your Arize AX account and create a tracing project from Projects → New Tracing Project. The setup page shows the credentials you need: copy your Space ID, then click Create API Key to generate a key and save it somewhere safe. You set them asARIZE_SPACE_ID and ARIZE_API_KEY when you configure your environment below, and they route your traces to the correct space.

- Python
- TypeScript
You need Python 3.10 or later, plus Node.js 18 or later and the Claude Code CLI (
npm install -g @anthropic-ai/claude-code), which the Agent SDK runs as a subprocess even from Python.1
Install the instrumentor
Install the OpenInference instrumentor for the Claude Agent SDK alongside the SDK and tracing dependencies.
2
Configure credentials
Set your Arize AX and Anthropic credentials as environment variables. The tracing setup reads them at startup, so you keep secrets out of your source.
ARIZE_PROJECT_NAME is the project your traces land in. Name it for the app so runs stay grouped where you expect them.3
Initialize tracing before the SDK runs
Set up tracing in a dedicated module so it runs once, before your agent code uses the SDK. Import this module before any
register() builds a tracer provider from your Arize credentials, and ClaudeAgentSDKInstrumentor().instrument(...) patches the SDK to emit spans.tracing.py
claude_agent_sdk import in your entry point. The instrumentor patches the SDK at import time, so an agent client created before instrumentation runs will not emit spans.main.py
If your app serves the SDK from a web framework such as FastAPI or Flask, instrument the Agent SDK itself. Web-server instrumentation records HTTP requests, not the agent, tool, and model activity that make up an agent trace.
4
Run your agent
Run the agent the way you already do. The instrumentor traces the run with no change to your agent logic.For multi-turn conversations that retain context,
ClaudeSDKClient is traced the same way, producing one AGENT span per response turn. Custom tools you register with the SDK’s in-process MCP server support are traced the same way too: each tool the agent invokes appears as a child span under the agent run, with its inputs and outputs.5
Group traces by conversation
Auto-instrumentation captures each run on its own. To follow a multi-turn conversation as a single thread, tag its runs with a shared session ID that is stable for the conversation, such as the user or thread ID. Wrap the agent call in the Every span emitted inside the block carries the same
using_session() context manager.session.id, so Arize AX groups the turns together and you can replay a full conversation.6
Verify in Arize AX
Open your Arize AX space and select the project you set in
ARIZE_PROJECT_NAME. Within about 30 seconds of a run, a new trace appears with an AGENT root span carrying the prompt as input, the result as output, and session.id, llm.model_name, and token-count metadata. Tools the agent invoked appear as child TOOL spans with their inputs and outputs.If no traces appear, see Troubleshooting.What gets captured
The Claude Agent SDK instrumentor records the shape of each agent run:- Agent spans. One AGENT root span per
query()call or perClaudeSDKClientresponse turn, carrying the prompt, the final result, the model name, and token counts. - Tool spans. One TOOL child span per tool invocation, with the tool name, inputs, and outputs, so you can see what the agent decided to do and what each tool returned.
- Session grouping. The
session.idyou set, which threads related runs into one conversation.
Capture model-level LLM spans
In Python, the Agent SDK instrumentor emits AGENT and TOOL spans, with the model name and token counts summarized on the agent span, but it does not emit a separate LLM span for each underlying model generation. To record per-generation input, output, and token usage as their own spans, add the Anthropic instrumentor next to this one in your tracing module:Troubleshooting
- Python
- TypeScript
- No traces in Arize AX. Confirm
ARIZE_SPACE_IDandARIZE_API_KEYare set in the same shell that runs your app. Enable OpenTelemetry debug logs withexport OTEL_LOG_LEVEL=debugand rerun. - Agent spans missing.
ClaudeAgentSDKInstrumentor().instrument(...)must run beforequery()orClaudeSDKClientis used. Make sure your tracing module is the first import in your entry point. claudeexecutable not found. The Agent SDK runs the Claude Code CLI as a subprocess. Install it withnpm install -g @anthropic-ai/claude-code, or point the SDK at an existing binary withCLAUDE_CODE_EXECUTABLE.401or404from Anthropic. VerifyANTHROPIC_API_KEYis set and valid, and that your key has access to the model your agent requests.- Tool spans expected but not present. TOOL spans emit only when the agent invokes a tool. Grant tools through
ClaudeAgentOptions(allowed_tools=[...])and give a prompt that requires them.
Next steps
Set up sessions
Group multi-turn runs into conversations with session and user IDs.
Customize your traces
Attach metadata, tags, and custom attributes to your spans.
Evaluate agents
Score tool selection, tool results, and goal completion.
Claude Agent SDK integration
The reference page for the instrumentor, including capturing model-level spans.