# How do I trace a Claude Agent SDK agent?

Set `CLAUDE_CODE_ENABLE_TELEMETRY=1` and an OTLP exporter for each signal you want. The SDK runs the Claude Code CLI as a child process, and the CLI does the actual exporting: metrics (`OTEL_METRICS_EXPORTER`) for token, cost, and session counters, structured log events (`OTEL_LOGS_EXPORTER`) for each prompt, API call, and tool result, and traces (`OTEL_TRACES_EXPORTER`) for spans around each interaction, model request, tool call, and hook. Traces are the one signal still in beta, so they also need `CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1`.

A subagent's spans nest under the parent's tool span, so a delegated task shows up inside the same trace as the loop that spawned it, rather than as a disconnected run. What doesn't come free is the content: prompt text, tool arguments, and full request bodies are opt-in, one environment variable each, so a fresh setup gives you shape and timing before it gives you what the agent actually said. Grading what it said is a separate job, closer to [replaying the turn that failed](/answers/failure-replay/how-do-i-replay-a-failed-agent-session-turn-by-turn) with its real context than to reading a span.

---

Sources:
- Claude Docs: Observability with OpenTelemetry: https://code.claude.com/docs/en/agent-sdk/observability (fetched 2026-09-11)

Source: https://tessary.ai/answers/claude-agent-sdk-evals/how-do-i-trace-a-claude-agent-sdk-agent
More on Claude agent sdk evals: https://tessary.ai/answers/claude-agent-sdk-evals
From Tessary, agent reliability for AI agents in production: https://tessary.ai
