What you will be able to do
- Explain why request logs cannot tell you why an agent run failed, and which spans and attributes can
- Roll out one OpenTelemetry collector configuration to every machine through managed settings, and know which keys developers can still override
- Tag telemetry with tenant, team and deployment attributes, and turn off the identity attributes your dashboards don't use
- Decide which content gates are worth turning on for a whole fleet, given what each one exposes
Key concept
Run-level telemetry — Telemetry that records an agent turn as a tree: one parent span for the turn, with child spans for each model request, tool call and subagent. You can then see how a run unfolded and where it went wrong, which a flat list of API calls cannot show.
1.Why agent runs resist ordinary debugging
A request log answers the wrong question for an agent. One prompt to an agent can turn into a dozen model requests, several tool calls, a wait for a human to approve a permission, and a subagent that makes its own requests. Each step depends on what the model chose in the step before, so running the same prompt twice can follow a different path. A log with one row per API call shows that request 7 returned max_tokens. It cannot show which turn request 7 belonged to, which agent sent it, or that the tool call before it waited four minutes for approval.
Tracing puts those relationships back. Each turn becomes a claude_code.interaction span. Model calls and tool calls nest under it, and a tool span has separate children for the permission wait and for the execution itself. When the Agent tool starts a subagent, the subagent's own request and tool spans nest under the tool call that started it.
claude_code.interaction
├── claude_code.llm_request
├── claude_code.hook (requires detailed beta tracing)
└── claude_code.tool
├── claude_code.tool.blocked_on_user
├── claude_code.tool.execution
└── (Agent tool) subagent claude_code.llm_request / claude_code.tool spansAttributes on the claude_code.llm_request span tell you where in a multi-agent run a request came from. agent_id identifies the subagent or teammate that sent the request, and parent_agent_id identifies the agent that spawned that one. query_source_safe gives a bounded name for the subsystem that sent it, such as repl_main_thread or agent.builtin.general-purpose. The same span also records attempt (how many attempts the request took), stop_reason, and, when the request failed, an error_class such as api_timeout or server_overload. Together these separate a run that ran out of output tokens from one that kept retrying an overloaded endpoint.
Claude Managed Agents gives you a similar view with no code. The session viewer in the Claude Console has a timeline with one lane per thread. Its Tools tab lists each configured tool with call counts, failures and median duration, so a tool that fails on every third call stands out. If you also want the API's own spans in your backend, add an OpenTelemetry destination in the Console. To nest those spans under your application's spans, call the SDK from inside one of your spans: the API reads the W3C traceparent header. Two delivery rules affect your queries. Delivery is at least once, so remove duplicates using the trace ID and span ID. Delivery is also best effort, so a lost span is never sent again.
Checkpoint 1 of 7· Fill the gap
A tool call in an agent turn sat idle for four minutes before it ran. In the span tree for one Claude Code or Agent SDK turn, which span under claude_code.tool records that wait for permission approval?
claude_code.interaction
├── claude_code.llm_request
├── claude_code.hook (requires detailed beta tracing)
└── claude_code.tool
├── ?
├── claude_code.tool.execution
└── (Agent tool) subagent claude_code.llm_request / claude_code.tool spansEach tool span has two separate children: claude_code.tool.blocked_on_user for the permission wait and claude_code.tool.execution for the run itself. That split lets you see that a slow tool call was waiting for a human, not running slowly. A flat log of API calls cannot show this.
Source: code.claude.comCheckpoint 2 of 7· Check yourself
A multi-agent run stalled. You need to tell whether a model request kept retrying an overloaded endpoint or just ran out of output tokens. What should you check?
The claude_code.llm_request span records attempt (how many tries the request took), stop_reason (for example max_tokens), and error_class when the request failed. Read together, these separate repeated server_overload retries from a request that hit its output limit. agent_id and parent_agent_id only show which agent sent the request.
“Short error class token when the request failed, such as api_timeout or server_overload”Source: code.claude.com
2.Rolling the collector config out through managed settings
Claude Code exports three signals, metrics, log events and traces, and each answers a different question (see Metrics, log events and traces: three signals, three questions). The problem at scale is getting hundreds of machines to send all three to the same collector in the same way. If developers set the variables in their own shell profiles, one typo or one forgotten export creates a silent gap. Instead, put the configuration in the env block of the administrator-managed settings.json, so it reaches every machine without any setup by each developer.
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://collector.example.com:4317",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer example-token"
}
}Managed transport settings take priority over the matching developer settings. Setting OTEL_EXPORTER_OTLP_ENDPOINT removes every per-signal endpoint a developer has set, so nobody can send one signal to a different collector. Setting OTEL_EXPORTER_OTLP_PROTOCOL does the same for protocols. Credentials go further. When managed settings supply OTEL_EXPORTER_OTLP_HEADERS or a client key or certificate, Claude Code also removes every endpoint a developer has set. Otherwise your token could be sent to a collector you did not choose.
Exporter selectors are the gap. OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER and OTEL_TRACES_EXPORTER follow normal per-key precedence, so any you leave out of managed settings can be changed on each machine. A selector set to console is the clearest case of telemetry that never arrives. The output appears in that developer's terminal and nowhere else, so the observability team gets no central view. Export intervals belong in managed settings too. Shorten them while debugging, then reset them for production, where the metric default is 60 seconds.
Agent SDK deployments have a matching rule. The recommended approach for production is to set the variables in the process environment: the shell, container or orchestrator. Every query() call then picks them up with no code change.
Checkpoint 3 of 7· Check yourself
Suppose your managed settings supply OTEL_EXPORTER_OTLP_HEADERS with the organization's bearer token. One developer has set OTEL_EXPORTER_OTLP_LOGS_ENDPOINT in their own settings to point at a personal collector. What does Claude Code do with that developer's logs endpoint?
Managed credentials do more than endpoints or protocols do. When managed settings supply headers or a client key or certificate, Claude Code also removes every developer-set endpoint, both generic and per-signal. Otherwise the organization's token could reach a collector the admin did not choose.
“plus every developer-set endpoint variable, generic or per-signal, since those credentials would otherwise reach a collector the managed settings didn’t choose.”Source: code.claude.com
3.Tagging telemetry per tenant, team and deployment
Fleet telemetry is useful only if you can split it into groups. A cost spike across 400 developers means little until you know which team, which service or which customer caused it. Two standard variables add that context to every signal: OTEL_SERVICE_NAME names the agent, and OTEL_RESOURCE_ATTRIBUTES carries comma-separated key=value pairs such as service.version=1.4.0,deployment.environment=production. The keys are your own choice, so a platform team can add whatever its finance reports group by, such as department or cost center.
In a multi-tenant service, the tags change with each request. The Agent SDK accepts the variables through per-call options, so you can tag each run with the user and tenant who triggered it. Values come from the request, so URL-encode them. In TypeScript, options.env replaces the inherited environment rather than merging with it. Spread process.env into it first, or the agent loses PATH and its API key.
The exporter configuration comment in the example below stands for the variables that turn telemetry on and say where it goes: CLAUDE_CODE_ENABLE_TELEMETRY, one exporter selector per signal (OTEL_METRICS_EXPORTER, OTEL_LOGS_EXPORTER, and for traces OTEL_TRACES_EXPORTER plus CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1), and the transport settings OTEL_EXPORTER_OTLP_PROTOCOL, OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS. In Python, the per-call env is merged on top of the inherited environment, so these can also come from the process environment and the per-call dict then needs only the tags.
from urllib.parse import quote
options = ClaudeAgentOptions(
env={
# ... exporter configuration from the Enable telemetry export example ...
# request is the incoming request object from your web framework.
"OTEL_RESOURCE_ATTRIBUTES": f"enduser.id={quote(request.user_id)},tenant.id={quote(request.tenant_id)}",
},
)Claude Code adds your resource attributes to every metric datapoint by default, which is what makes splitting metrics by team possible. It also adds identity attributes you may not need. session.id and the account attributes are on by default, so a fleet sending them gets new attribute values on its metrics with every session and every developer. If your dashboards only ever group by team, turn off the flags they don't use. That keeps the number of distinct time series, and the backend storage bill, from growing with headcount.
| Variable | Adds | Default |
|---|---|---|
| OTEL_METRICS_INCLUDE_RESOURCE_ATTRIBUTES | Keys from OTEL_RESOURCE_ATTRIBUTES on metric datapoints | true |
| OTEL_METRICS_INCLUDE_SESSION_ID | session.id (and ccr.session.id on cloud sessions) | true |
| OTEL_METRICS_INCLUDE_ACCOUNT_UUID | user.account_uuid and user.account_id | true |
| OTEL_METRICS_INCLUDE_VERSION | app.version | false |
| OTEL_METRICS_INCLUDE_ENTRYPOINT | app.entrypoint | false |
| OTEL_METRICS_INCLUDE_REPOSITORY | vcs.* repository identity | false |
API-side spans are separated by workspace instead. A Console destination covers All workspaces, Selected workspaces, or All except the ones you list. The API sends each span to every enabled destination that covers the workspace where the request ran. With separate production and staging workspaces, a destination set to Selected can send only production traffic to the expensive backend.
Checkpoint 4 of 7· Fill the gap
Your multi-tenant service runs one agent per incoming request. Each run's telemetry must carry the end user and tenant who triggered it. Which variable name completes this per-call option?
from urllib.parse import quote
options = ClaudeAgentOptions(
env={
# ... exporter configuration from the Enable telemetry export example ...
# request is the incoming request object from your web framework.
" ? ": f"enduser.id={quote(request.user_id)},tenant.id={quote(request.tenant_id)}",
},
)OTEL_RESOURCE_ATTRIBUTES holds comma-separated key=value pairs that are added to every signal. The values come from the request, so they are URL-encoded. OTEL_SERVICE_NAME only names the agent, and OTEL_METRICS_INCLUDE_RESOURCE_ATTRIBUTES is a true/false flag, not the place for tags.
Source: code.claude.comCheckpoint 5 of 7· Check yourself
Your fleet's dashboards group Claude Code metrics only by a team key set in OTEL_RESOURCE_ATTRIBUTES. Even so, the backend's time-series count and storage bill keep growing with every new developer and session. Which change fixes this without losing the team split?
session.id and the account attributes are on metrics by default, so each new session and developer adds attribute values and new time series. Turning off those two flags stops that growth. Turning off the resource-attributes flag would remove the team key the dashboards depend on, and the version and entrypoint flags are already false by default.
“OTEL_METRICS_INCLUDE_SESSION_ID | Include session.id and, on cloud sessions, ccr.session.id attributes in metrics | true | false”Source: code.claude.com
Checkpoint 6 of 7· Exam question
An enterprise is rolling out centrally managed OpenTelemetry export for Claude Code across 400 engineers on Kubernetes, and the observability team wants configuration that scales without per-developer setup and keeps backend storage costs predictable. Which combination of practices should they adopt? (Select all that apply)(Select 3)
Correct answers: A, B, C — Set the telemetry environment variables in the administrator-managed settings.json rather than relying on each developer's shell profile; Add custom OTEL_RESOURCE_ATTRIBUTES such as department and cost_center so spend and usage can be sliced by team in the backend; Turn off OTEL_METRICS_INCLUDE_SESSION_ID and similar cardinality flags that are not needed for the team's dashboards to limit unique time-series growth
- A. Correct. Centralizing telemetry variables in administrator-managed settings.json applies the same collector endpoint and exporter choices to every developer without relying on individual shell configuration, which is the documented enterprise pattern.
- B. Correct. Custom resource attributes like department, team.id, and cost_center are the documented mechanism for multi-team attribution, letting the backend break down token and cost metrics per group.
- C. Correct. High-cardinality attributes such as session.id or account UUIDs multiply the number of unique time series a metrics backend must store; disabling the ones a dashboard does not need is the documented way to control that cost as headcount grows.
- D. The console exporter writes telemetry to the same standard output channel the SDK/CLI uses for other output and is documented as unsuitable for anything beyond local debugging; it is not a scalable production export target.
- E. Requiring per-developer manual shell exports is exactly the fragile, non-scalable setup that centrally managed settings.json is meant to replace, and it invites drift across 400 machines.
4.Which content is worth collecting at scale
Content is redacted by default, and each gate you open exposes more of every session on every machine (see Telemetry content gates (redacted by default)). The decision at scale is about exposure, not capability. One developer turning on prompt logging affects one person's sessions. The same gate in managed settings sends every engineer's prompts to a shared backend that many people can query.
Some data reaches your backend even with every gate closed. Under OAuth, user.email is a telemetry attribute. It goes only to your collector, never to Anthropic, but your backend now stores it, so filter it there if your policy requires. The widest gate, OTEL_LOG_RAW_API_BODIES, emits full request and response bodies, including the entire conversation history. Turning it on counts as consenting to everything the prompt, tool-detail and tool-content gates would reveal. It is rarely the right choice for a whole fleet.
A narrower choice usually meets the real need. A security team auditing which commands ran needs OTEL_LOG_TOOL_DETAILS, sent as log events to a SIEM, not prompt text. Even that exposes a lot: fields such as full_command are emitted untruncated, and commands can contain secrets.
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_LOG_TOOL_DETAILS": "1",
"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://siem.example.com:4318/v1/logs",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer your-siem-token"
}
}Gates that interact are easy to get wrong. When OTEL_LOG_ASSISTANT_RESPONSES is unset, it takes the value of OTEL_LOG_USER_PROMPTS, so opening prompts also opens responses unless you set the response gate to 0. If you collect prompts and strip them later in the collector, delete both attributes that carry the text, prompt and prompt_text. A rule that names only one leaves the prompt in storage.
Checkpoint 7 of 7· Fill the gap
A security team needs to audit which commands ran on every developer machine, with log events going to their SIEM, without collecting what developers typed to Claude. Which gate completes this managed-settings pipeline?
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_LOGS_EXPORTER": "otlp",
" ? ": "1",
"OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://siem.example.com:4318/v1/logs",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer your-siem-token"
}
}OTEL_LOG_TOOL_DETAILS adds tool parameters such as Bash commands to tool events. That is the narrow gate a command audit needs. OTEL_LOG_USER_PROMPTS would collect prompt text. OTEL_LOG_RAW_API_BODIES would send the entire conversation history and counts as consenting to every other content gate. Even this narrow gate needs care, because fields like full_command are not truncated and can contain secrets.
Source: code.claude.comSources1
Sources
(4)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.https://code.claude.com/docs/en/monitoring-usageOfficial docs
“Identifier of the agent that spawned this one.”
↩︎ Why agent runs resist ordinary debugging“Developers can’t point one signal at a different collector”
↩︎ Rolling the collector config out through managed settings“since those credentials would otherwise reach a collector the managed settings didn’t choose”
↩︎ Rolling the collector config out through managed settings“Include keys from OTEL_RESOURCE_ATTRIBUTES as attributes on metric datapoints”
↩︎ Tagging telemetry per tenant, team and deployment“When authenticated via OAuth, user.email is included in telemetry attributes, sent only to the OTel endpoint you configure, never to Anthropic.”
↩︎ Which content is worth collecting at scale“Fields such as full_command are emitted untruncated”
↩︎ Which content is worth collecting at scale“If you drop or mask the event’s prompt text by attribute name in your collector, name both attributes in the rule”
↩︎ Which content is worth collecting at scale“A developer’s setting can still disable a signal or switch it to the console exporter, so set the selectors in managed settings too”
↩︎ Exam trap 1“Include session.id and, on cloud sessions, ccr.session.id attributes in metrics | true | false”
↩︎ Exam trap 2“Enabling this implies consent to everything OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, and OTEL_LOG_TOOL_CONTENT would reveal”
↩︎ Exam trap 3“Short error class token when the request failed, such as api_timeout or server_overload”
↩︎ Checkpoint“A developer’s setting can still disable a signal or switch it to the console exporter, so set the selectors in managed settings too”
↩︎ Prediction“plus every developer-set endpoint variable, generic or per-signal, since those credentials would otherwise reach a collector the managed settings didn’t choose.”
↩︎ Checkpoint“OTEL_METRICS_INCLUDE_SESSION_ID | Include session.id and, on cloud sessions, ccr.session.id attributes in metrics | true | false”
↩︎ Checkpoint - 2.
“Timeline minimap: A zoomable overview of the session's activity over time, with one lane per thread in multiagent sessions.”
↩︎ Why agent runs resist ordinary debugging - 3.
“A destination can receive the same span more than once. To remove duplicates, use the trace ID and span ID.”
↩︎ Why agent runs resist ordinary debugging“The API sends spans to every enabled destination that covers the workspace where the request or session runs.”
↩︎ Tagging telemetry per tenant, team and deployment - 4.
“This is the recommended approach for production deployments.”
↩︎ Rolling the collector config out through managed settings“Use this when different agents in the same process need different telemetry settings.”
↩︎ Tagging telemetry per tenant, team and deployment“In Python, env is merged on top of the inherited environment.”
↩︎ Tagging telemetry per tenant, team and deployment“wraps a single turn of the agent loop, from receiving a prompt to producing a response.”
↩︎ Key concept