Observability and Monitoring for Agents at Scale
What the platform gives you
- The Agent SDK exports OpenTelemetry traces, metrics and log events over OTLP to any compatible backend (hosted platform or self-hosted collector): which tools were called, how long each model request took, tokens spent where, where failures occurred.
- Claude Code enables export with
CLAUDE_CODE_ENABLE_TELEMETRY=1and standard OTel variables (OTEL_METRICS_EXPORTER,OTEL_LOGS_EXPORTER,OTEL_EXPORTER_OTLP_PROTOCOL,OTEL_EXPORTER_OTLP_ENDPOINT,OTEL_EXPORTER_OTLP_HEADERS); administrators can set these for all users through managed settings. - Metrics include
claude_code.token.usage,claude_code.cost.usage,claude_code.session.count,claude_code.lines_of_code.count,claude_code.commit.count,claude_code.pull_request.count,claude_code.active_time.total,claude_code.code_edit_tool.decision. Attributes such asskill.name,plugin.nameandagent.nameattribute spend to skills, plugins and subagent types. - Cost figures are approximations: SDK
total_cost_usdand the cost metric are client-side estimates from a bundled price table; use your provider's billing data (Console, Bedrock, Google Cloud) as the authoritative source. Data-residency pricing is modelled (a 1.1 multiplier when a response reportsinference_geo: "us"). - API responses expose
usage(input, output, cache creation, cache read tokens) and astop_reason; messages from inside a subagent carryparent_tool_use_id(andagent_idin TypeScript). - Hooks (
PreToolUse,PostToolUse,SubagentStop,Notification) support audit logging; an async hook can log without blocking. - The platform also has a usage and cost API, an admin API, and a Compliance API for activity and session data (existence verified; see admin docs).
What to monitor (design guidance)
| Area | Signals |
|---|---|
| Cost | Tokens and spend per request, user, team, agent, skill; budget burn; cost per completed task |
| Latency | Time to first token, total time, tool latency, queue time; p50 and p95 |
| Reliability | Error and retry rates, stop_reason mix (max_tokens, refusal, model_context_window_exceeded), tool failures, timeouts |
| Quality | Evaluation scores on sampled traffic, validator failures, user ratings, escalation rate |
| Efficiency | Cache hit rate, tool calls per task, turns per task, context size growth |
| Safety | Denied tool calls, guardrail trips, injection signals, refusals |
Operating practice (design guidance)
- Trace a request end to end (a trace id across orchestrator, subagents and tools).
- Alert on thresholds and anomalies (cost spike, rising refusal or error rate, falling cache hits, quality drop).
- Sample and review outputs; feed failures into the evaluation set (D1.4).
- Respect privacy: telemetry and logs can contain sensitive prompts; redact, restrict access and set retention (D5.4).
- Set budgets and caps so monitoring has teeth (
maxBudgetUsd, workspace limits).
Exam traps
- Treating client-side cost estimates as the bill.
- Monitoring cost only, not quality.
- Logging raw sensitive prompts with open access.
- No trace correlation across subagents.
- Alerts without an owner.
References
- Observability with OpenTelemetry (Agent SDK) — checked Oct 16, 2026
- Monitoring usage — checked Oct 16, 2026
- Track cost and usage — checked Oct 16, 2026
Check your understanding
Which source is authoritative for billing?Show answerHide answer
Answer
The provider's billing data, not client-side estimates.How do you attribute spend to a specific subagent type?Show answerHide answer
Answer
Telemetry attributes such asagent.nameon the usage metrics.Name two stop reasons worth alerting on.Show answerHide answer
Answer
max_tokens(truncation) andrefusal.