What you will be able to do
- Add a Claude API OpenTelemetry destination and nest its spans under your application's traces
- Read a Managed Agents session's usage and list cost
- Query the Usage & Cost Admin API at a granularity and polling rate that fit the monitoring need
- Name what the Claude Code analytics dashboard and compliance activities record, and route Claude Code log events to a SIEM
1.Tracing Messages API requests and Managed Agents sessions
Claude Code and the Agent SDK export OpenTelemetry metrics, log events and traces from the process that runs them. That covers one client at a time. Watching a whole organisation takes four further streams, each answering a different question: spans emitted by the Claude API itself, the usage and cost of individual Managed Agents sessions, organisation-wide usage and cost reports, and adoption and audit records. This page covers each in turn. A Managed Agents session is a run of an agent on the Claude Platform, with its own threads, tools and usage totals, which you can inspect in the Claude Console.
Client-side telemetry stops at your process boundary. The Claude API can emit its own spans, one for each model request and each tool use it runs on Messages API requests and Managed Agents sessions, without any code change. You receive them by adding a destination: an OTLP/HTTP endpoint that accepts protobuf over HTTPS on port 443, plus the headers that authenticate to it. Only organisation admins can add or change destinations. A destination covers All workspaces, Selected ones, or All except a list. Its content mode is either Metadata only or Full content. That is the same opt-in idea as in Claude Code, which redacts prompt, response and tool content by default and records it only when you switch it on.
client = anthropic.Anthropic()
destination = client.beta.organization.telemetry_destinations.create(
endpoint_url="https://gateway.example.com/otlp",
headers={"authorization": "Bearer YOUR_OBSERVABILITY_API_KEY"},
traces={"content_mode": "metadata_only"},
workspaces={"type": "all"},
)
print(destination.id)Leave /v1/traces off the endpoint URL, because the API appends it. After saving, run Test from the destination's menu and look for an anthropic.test span. Real spans arrive under service.name = claude-platform. If you run your own Collector, note that its OTLP/HTTP receiver listens on port 4318 by default. Either reconfigure it for HTTPS on 443 or put a reverse proxy in front.
On their own, API spans start their own traces. To nest them under your application's spans, call the SDK from inside one of your own spans. The SDK writes a W3C traceparent header, and your sampler controls its sampled flag. When the flag is off, the API emits no spans for that request. The same propagation continues into MCP servers connected through the MCP connector, which receive a traceparent in params._meta and can attach their own spans.
Delivery is at least once and best effort. Expect duplicate spans and deduplicate on trace ID plus span ID. A lost span is never resent. The Console's Delivery column shows Healthy, Failing, No data or Disabled. The API disables a destination that answers with a 3xx redirect, resolves to a non-public IP, or fails every delivery for 24 hours.
Checkpoint 1 of 6· Fill the gap
An admin is adding a destination so the Claude API sends spans to their observability platform's OTLP/HTTP gateway. Which endpoint URL goes in the blank?
client = anthropic.Anthropic()
destination = client.beta.organization.telemetry_destinations.create(
endpoint_url=" ? ",
headers={"authorization": "Bearer YOUR_OBSERVABILITY_API_KEY"},
traces={"content_mode": "metadata_only"},
workspaces={"type": "all"},
)
print(destination.id)Use the base HTTPS URL on port 443. Leave /v1/traces off because the API adds it, and don't use the Collector's default plain-HTTP port 4318, because the destination must accept HTTPS on 443.
Source: platform.claude.comCheckpoint 2 of 6· Check yourself
An organisation has a destination covering all workspaces. Their application calls the SDK inside its own spans, and its sampler keeps only 10% of traces. What happens to the API spans for the other 90% of Messages API requests?
The SDK's traceparent header carries your sampler's decision. When the sampled flag is off, the API doesn't emit the request's span or any child span, so a covered workspace doesn't mean every request is traced.
“If the sampled flag in the header is off, the API doesn't emit the request's span or the spans under it.”Source: platform.claude.com
2.Usage and cost of a Managed Agents session
A single Managed Agents session reports its own consumption. The session object's usage field holds cumulative token counts, cache reads and writes, server tool requests, active_seconds and list_cost. A session can run several threads, for example one per agent in a multiagent session, and the Console's session viewer shows one timeline lane per thread, a transcript, and a Tools tab with failure counts and median duration. active_seconds is the time during which at least one thread was running, with overlapping threads counted once. The session's running-time cost is priced on that duration. Each thread also reports its own list_cost, but per-thread costs are rounded independently and leave out the running-time cost, so the session figure is the authoritative one.
A session.usage event carries the same cumulative snapshot on the session stream, so you don't have to poll. It is emitted on idle transitions rather than on a timer: immediately before the session goes idle, and when a thread pauses at a session budget. During a long run you therefore see no new totals until one of those moments. That is why a spend cap built from watching usage and stopping the session yourself fails, since the stop arrives after the money is spent. A session budget is a dollar cap on list cost. The platform prices consumption continuously and pauses each thread before its next model request once the cap is reached, so enforcement doesn't depend on your code noticing in time.
Checkpoint 3 of 6· Check yourself
Your team runs long Managed Agents sessions and must make sure none of them goes past a fixed dollar amount at list price. Which approach should you build?
A session budget is the tool for capping spend. Watching usage and stopping the session yourself is the wrong approach. session.usage events only arrive just before an idle transition, so they can't stop a run partway through. Per-thread costs leave out running-time cost, so adding them up gives a figure below the session's real spend.
“To enforce a spend limit, set a session budget rather than polling usage and stopping the session yourself.”Source: platform.claude.com
Sources2
3.Usage & Cost Admin API: organisation-wide trends
The Usage & Cost Admin API answers organisation-wide questions: tokens by model, workspace, API key or service tier over time, and spend by day. You call it with an Admin API key. The response is a series of time buckets, and bucket_width sets their granularity. Each width has its own default and maximum limit, which is the number of buckets returned per request. The cost endpoint offers only daily buckets.
| bucket_width | Default limit | Maximum limit | Fits |
|---|---|---|---|
| 1m | 60 buckets | 1440 buckets | Incident watch and minute-level spikes |
| 1h | 24 buckets | 168 buckets | A week at hourly resolution |
| 1d | 7 buckets | 31 buckets | Monthly trends and chargebacks |
bucket_width sets granularity, not refresh rate. Usage and cost data typically shows up within 5 minutes of a request completing. So for incident monitoring, use 1m buckets, raise limit past the default 60 when you need a longer window, and poll about once a minute. Short bursts of faster requests are fine for paging through results. For a dashboard that many people refresh, cache the responses instead of calling the API on every page load.
Checkpoint 4 of 6· Check yourself
Finance wants a report of last month's token use broken down by model and workspace across the whole organisation, with spend per day. Where should this data come from?
The session usage field, session.usage events and the session viewer each describe one session, so adding them up does not give organisation-wide totals by model or workspace. The Usage & Cost Admin API answers organisation-wide questions in time buckets, and its cost endpoint offers daily buckets.
“The session object includes a usage field with the session's cumulative usage: token counts, server tool use, active time, and the tracked list cost.”Source: platform.claude.com
Checkpoint 5 of 6· Exam question
During an active incident, an on-call engineer needs a near real-time view of organization-wide token consumption spikes, checking for anomalies roughly once a minute. Which Usage API configuration fits this monitoring need within the documented granularity limits?
Correct answer: A — Request bucket_width=1m, raise the limit above the 60-bucket default up to the 1440-bucket maximum as needed, and poll about once per minute
- A. Correct. Minute-level buckets are intended for real-time monitoring, the limit can be raised well past its default to capture a longer recent window, and roughly once-per-minute polling matches the documented sustained polling guidance.
- B. Incorrect. Daily buckets aggregate an entire day into one data point, which cannot reveal minute-level spikes during an active incident regardless of how many buckets are requested.
- C. Incorrect. Hourly buckets aggregate a full hour of usage into a single value; they do not refresh at 60-second intervals, and they are too coarse to spot a spike within a given hour.
- D. Incorrect. Polling far more frequently than the recommended once-per-minute cadence does not produce fresher underlying data, since usage figures typically finalize within about five minutes of request completion, and it needlessly increases API load.
4.Adoption analytics, audit events and SIEM routing
Spend data shows what Claude Code costs. Adoption data shows whether people use it. The Claude Code analytics dashboard reports usage metrics: lines of code accepted, suggestion accept rate, and daily active users and sessions. Teams and Enterprise plans add contribution metrics from a GitHub integration, such as merged PRs that contain Claude Code lines, plus a leaderboard and CSV export. On API organisations the dashboard lives in the Claude Console and adds spend tracking and team insights.
Administrative actions are a different stream again. The compliance activities endpoint lets you query actions such as workspaces being created or archived, members being added or removed, RBAC custom roles being created or assigned, spend limits being changed, and the zero data retention override being toggled. It also logs reads: viewing the Claude Code usage report or the messages usage report is itself an activity.
Claude Code's per-user activity reaches a retention store such as a SIEM through the logs exporter. Managed settings are the policy settings an admin deploys and enforces across all Claude Code users, so they are the right place for this configuration. When managed settings set an endpoint or credential, Claude Code removes any per-signal endpoints a developer set, so a developer can't send logs to a different collector. Three switches matter here. CLAUDE_CODE_ENABLE_TELEMETRY=1 turns telemetry collection on, and nothing is exported without it. OTEL_LOGS_EXPORTER=otlp sends log events to an OTLP endpoint, where none would disable them. OTEL_LOG_TOOL_DETAILS=1 is an opt-in that is off by default: it makes tool events carry the Bash commands and MCP server and tool names that ran, where otherwise those arguments are not logged.
{
"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"
}
}Checkpoint 6 of 6· Fill the gap
Security wants its SIEM to keep a per-user record of the Bash commands and MCP tools each developer's Claude Code ran. Only log events are exported to the SIEM. Which variable belongs in the blank?
{
"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 makes tool events name the Bash commands and MCP tools that ran. OTEL_LOG_TOOL_CONTENT records tool output on a span event and needs tracing, which this logs-only setup doesn't have. OTEL_LOG_USER_PROMPTS exposes prompts, not tools. OTEL_LOG_RAW_API_BODIES dumps whole conversations, which is far more than the audit needs.
Source: code.claude.comSources
(9)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“the Claude API can emit a span for each model request and each tool use that it runs.”
↩︎ Tracing Messages API requests and Managed Agents sessions“If the sampled flag in the header is off, the API doesn't emit the request's span or the spans under it.”
↩︎ Tracing Messages API requests and Managed Agents sessions“At least once: A destination can receive the same span more than once.”
↩︎ Tracing Messages API requests and Managed Agents sessions“If the sampled flag in the header is off, the API doesn't emit the request's span or the spans under it.”
↩︎ Exam trap 2 - 2.
“Use the session viewer in the Claude Console to inspect what an agent did in a session, without writing any code.”
↩︎ Tracing Messages API requests and Managed Agents sessions“The session's cumulative consumption priced at public list rates, as a whole number of cents in a string, with a currency code.”
↩︎ Usage and cost of a Managed Agents session“To enforce a spend limit, set a session budget rather than polling usage and stopping the session yourself.”
↩︎ Usage and cost of a Managed Agents session“The event is emitted on idle transitions rather than on a timer:”
↩︎ Usage and cost of a Managed Agents session“The session object includes a usage field with the session's cumulative usage: token counts, server tool use, active time, and the tracked list cost.”
↩︎ Checkpoint - 3.https://platform.claude.com/docs/en/api/beta/organization/usage_report/retrieve_messagesOfficial docs
“Default of 60 minutes, maximum of 1440 minutes”
↩︎ Usage & Cost Admin API: organisation-wide trends - 4.
“The API supports polling once per minute for sustained use.”
↩︎ Usage & Cost Admin API: organisation-wide trends“Usage and cost data typically appears within 5 minutes of API request completion”
↩︎ Exam trap 1 - 5.
“1d (1 day): Only option available, max 31 buckets per request”
↩︎ Usage & Cost Admin API: organisation-wide trends - 6.https://code.claude.com/docs/en/analyticsOfficial docs
“Usage metrics: lines of code accepted, suggestion accept rate, daily active users and sessions”
↩︎ Adoption analytics, audit events and SIEM routing - 7.
“The Claude Code usage report was viewed.”
↩︎ Adoption analytics, audit events and SIEM routing“Admin created an RBAC custom role.”
↩︎ Adoption analytics, audit events and SIEM routing - 8.https://code.claude.com/docs/en/monitoring-usageOfficial docs
“Developers can’t point one signal at a different collector”
↩︎ Adoption analytics, audit events and SIEM routing“Enables telemetry collection (required)”
↩︎ Adoption analytics, audit events and SIEM routing - 9.
“Deploy and enforce settings across all Claude Code users to match internal policies”
↩︎ Adoption analytics, audit events and SIEM routing