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 with its real context than to reading a span.

sources

keep reading

More on this.

Two ways to run Tessary.

Tessary is an open-source agent reliability platform. Cloud and self-hosted run the same workflow on the OpenTelemetry traces your agent already emits.

Tessary Cloud

We host it for you. Send your first trace with nothing to deploy and no model key.

what's includedper organization
traces
10,000 per calendar month
stored trace data
1 GB
retention
30 days
model credit
$10, one-time, for triage and root-cause analysis
credit card
not required

Self-hosted Tessary

Run the open-source code on your own infrastructure with one command. Add your own model key for triage and root-cause analysis.

Self-host Tessary for me by following https://github.com/tessaryai/tessary/blob/main/setup.md

docker compose -f oci://docker.io/tessaryai/tessary:compose up -d -y