CertSafari
    Anthropic Claude Certified Architect – Professional (CCAR-P)· Lessons

    Domain 3 · Lesson 15/38

    Run-level telemetry and tagging for Claude agent fleets

    Analyze observability challenges and select monitoring strategies at scale

    15 min read
    2.38% of exam
    4 sources
    Published 19 Oct 2026
    Docs as of 14 Oct 2026

    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.

    The span tree for one Claude Code or Agent SDK turntext
    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 spans

    Attributes 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 spans

    Checkpoint 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?

    Sources123

    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.

    Telemetry variables set once in managed settingsjson
    {
      "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?

    Sources14

    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.

    Tagging each agent run with the end user and tenant from the incoming request (Python)python
    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.

    Attribute flags on Claude Code metrics and their defaults
    VariableAddsDefault
    OTEL_METRICS_INCLUDE_RESOURCE_ATTRIBUTESKeys from OTEL_RESOURCE_ATTRIBUTES on metric datapointstrue
    OTEL_METRICS_INCLUDE_SESSION_IDsession.id (and ccr.session.id on cloud sessions)true
    OTEL_METRICS_INCLUDE_ACCOUNT_UUIDuser.account_uuid and user.account_idtrue
    OTEL_METRICS_INCLUDE_VERSIONapp.versionfalse
    OTEL_METRICS_INCLUDE_ENTRYPOINTapp.entrypointfalse
    OTEL_METRICS_INCLUDE_REPOSITORYvcs.* repository identityfalse

    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)}",
        },
    )

    Checkpoint 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?

    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)

    0 of 3 selected

    Sources143

    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.

    An audit pipeline: log events with tool details only, sent to a SIEMjson
    {
      "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"
      }
    }

    Sources1

    Sources

    (4)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “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. 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. 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. 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

    Continue to part 2 of 2

    Choosing a Claude monitoring strategy: OpenTelemetry, usage reports or a gateway

    Spotted a mistake, or was something unclear? Tell us.