What you need to know
An agent request is a tree: model calls, tool calls, retries and subagents. One log line per request with the total latency and the final answer cannot explain a 50-second request or a wrong answer. Instrumentation for Claude systems has to show the tree, count every token category, and do it without storing content that privacy rules forbid.
Traces for agent loops
| Span | Key attributes |
|---|---|
| Request (root) | Request and trace IDs, tenant or user ID (pseudonymous), route, prompt version, model snapshot |
| Model call | Model, input, output, cache-read and cache-creation tokens, stop reason, latency, time to first token |
| Tool call | Tool name, server and version, duration, error flag and error category, result size |
| Retry | Attempt number, error type, backoff |
| Subagent | Parent span, its own model and tool spans |
Propagate the trace context into subagents and tool services; without it, their work shows up as orphaned traces that cannot be joined to the request. Errors should be recorded as structured types (rate limit, overloaded, invalid request), not just success or failure, so dashboards can separate them.
Token and cost metrics
With caching on, input_tokens excludes the cached prefix. True input is:
input_tokens + cache_read_input_tokens + cache_creation_input_tokens
each priced at its own rate (cache reads cheaper, cache writes dearer than normal input). A cost metric built from input and output tokens alone under-reports spend once caching is on. For attribution, tag every request with tenant and feature identifiers at the gateway and record them on its usage event.
Cache diagnostics
| Signal | Likely cause |
|---|---|
| Cache reads near zero, creation near zero | Prefix below the model's minimum cacheable length (no error is raised) |
| Creation high on nearly every request | Something before the breakpoint changes per request: a timestamp, a user ID, tool order |
| Creation spikes at intervals | Entries expiring between requests; consider the longer lifetime |
| Read share falls after a release | The release changed or reordered the prefix |
Track cache-read tokens as a share of total input and cache-creation tokens over time per route.
Grounding and reasoning traceability
To classify a wrong answer, the trace must show what evidence the model had: retrieved passage IDs and versions, retrieval scores, and the citations used. For reasoning, request summarized thinking where the model hides thinking text by default, and store it under the same content policy as other captured content.
Structured events with a shared schema
A standard event for every Claude call lets logs from many services be queried together. Include identifiers that join the event to its trace, the model snapshot and prompt version, tokens by category, and typed errors. Never log API keys, and avoid free-text fields that each team writes differently.
Content capture under privacy constraints
Zero data retention concerns what the provider retains; your own observability is your responsibility. Where policy forbids storing message content:
- capture metadata (tokens, latency, stop reasons, tool names, error codes, versions) with content capture off by default;
- where debugging content is allowed, enable it per conversation with recorded consent, redact identifiers before storage, and keep it for the shortest period allowed, under a retention policy separate from metrics.
Claude Code can export OpenTelemetry metrics and events to an organization's collector, configured centrally through managed settings; it includes prompt text only when that is explicitly enabled.
In the exam
Telemetry items describe something the team cannot see (where time went, why cost differs from the bill, why cache hits fell, why an answer was wrong) under a stated privacy rule. Choose the instrumentation that makes the missing fact visible without breaking the rule. Distractors log everything, log nothing, add averages, or rely on the model's self-reports.
Check your understanding
With caching on, finance says spend is higher than the dashboard. Which correction is needed?
Show answer
Answer: A. input_tokens excludes cached tokens, so reads and writes must be added at their own prices.
Cache hit rate fell from 80% to 5% after a release that shortened the instructions. No errors appear. Why?
Show answer
Answer: B. Below the minimum, requests succeed but nothing is cached, and the usage fields show it.
A bank forbids storing customer message content in observability. What telemetry design fits?
Show answer
Answer: D. Metadata supports debugging and metrics without storing content; any stored content breaks the policy.
Apply it: Instrument Cobalt's triage agent
Cobalt's triage agent currently writes one log line per message: the urgency it assigned and the total time. Engineers cannot tell why some urgent messages take 12 minutes to reach a nurse, and finance's bill is 20% above the team's cost dashboard. The privacy officer forbids message content in observability, except for consented debugging cases kept for 14 days.
- Define the spans and their attributes for one triage request.
- Fix the cost metric.
- Specify the content-capture rules.
- Name two cache signals to put on the dashboard, and what each would reveal.
Show model answer
1. Spans. Root span per message (trace ID, pseudonymous patient ID, route, prompt version, model snapshot, assigned urgency). Child spans for each model call (tokens by category, stop reason, time to first token, latency), each tool call (lookup_patient, get_care_plan, search_protocols, propose_appointment, draft_reply; duration, error category), retries (attempt, error type), and the wait for nurse approval. The approval wait span answers the 12-minute question.
2. Cost. Cost per call = input x input price + cache reads x read price + cache writes x write price + output x output price, summed per message and tagged with route. The missing 20% is almost certainly cache writes and reads left out of the old formula.
3. Content capture. Off by default. A consented debugging case enables capture for that conversation only, with identifiers redacted before storage, stored separately from metrics, deleted after 14 days, and every access logged.
4. Cache signals. Cache-read share of total input per route (falls if a release changes the prefix) and cache-creation tokens per hour (rises if per-request data was placed before the breakpoint or entries expire between messages).