OpenTelemetry export is in beta at Anthropic. Span names and attributes can change during the beta. See Anthropic’s OpenTelemetry for the Claude API guide for the full reference.
What gets traced
- Messages API requests: one
anthropic.messages.createspan per request, with ananthropic.model_requestspan for each model run inside it. - Managed Agents sessions: a span per Sessions API request and an
anthropic.session.turnspan per agent turn, with the model requests, tool uses and outcome evaluations of that turn under it. - Server tools and MCP tools: a tool span (
anthropic.tool_use,anthropic.mcp_tool_use) for each tool the API runs, such as web search, code execution or a tool on an MCP server you connect with the MCP connector. - Token usage on the request and model request spans.
How it works
There are two sources of spans, and you can use either one or both.
API export works for Claude Platform and Claude Platform on AWS. On Claude Platform on AWS, the API spans always start their own traces.
Add a LangWatch destination
You need the admin role in your Claude Console organisation and a LangWatch API key from your project settings.1
Open the OpenTelemetry settings
In the Claude Console, open the OpenTelemetry settings page and click Add destination.
2
Fill in the destination
Leave OTLP traces endpoint URL empty. Anthropic adds
/v1/traces to the OTLP endpoint URL itself, so do not add it.The X-Auth-Token: <LANGWATCH_API_KEY> header also works in place of Authorization. With a service API key, add an X-Project-Id header with your project ID.3
Save
Click Add destination. The Console does not show the header values again after you save.
Content size. LangWatch keeps up to 256 KB for each attribute value for now, and this limit will be raised. Setting the maximum content size to
0.25 MB makes Anthropic shorten long prompts and responses itself and set anthropic.content.truncated to true on the span, so you can see which spans were cut.Self-hosted LangWatch
Use your own LangWatch base URL with/api/otel, for example https://langwatch.example.com/api/otel, and an API key from your instance. Anthropic only delivers to an HTTPS hostname on port 443 that resolves to a public IP address, so the instance must be reachable from the internet.
Test it
- On the OpenTelemetry settings page, open the destination’s More actions menu and click Test. The Console sends an
anthropic.testspan and shows whether it was delivered. - Send a Messages API request in the Console playground or from your application, in a workspace the destination covers.
- Check that the Delivery column shows Healthy. This can take about a minute.
- In LangWatch, open your project’s traces and filter on
service.name=claude-platform, the service name of every API span.
Read your trace
For a Messages API request, the trace has ananthropic.messages.create span with one anthropic.model_request span for each model run and a tool span for each server or MCP tool the API ran.
- Input and output are on
anthropic.messages.create. The system prompt is ingen_ai.system_instructions, the messages ingen_ai.input.messagesand the response ingen_ai.output.messages. - On
anthropic.model_requestspans you see no input or output, by design. These spans hold the model, timing and token usage of each model run. An empty input there does not mean content export failed: open the parentanthropic.messages.createspan to read the content. - Tool spans hold the tool arguments in
gen_ai.tool.call.argumentsand the result inanthropic.tool_result.content.
anthropic.session.turn spans. A thread’s first turn holds the system prompt, gen_ai.input.messages holds what came into the turn and gen_ai.output.messages what the agent produced. A session can span several traces: gen_ai.conversation.id holds the session thread ID and anthropic.session.id the session ID, so you can group spans by either.
With both API and SDK export, each request appears as two anthropic.messages.create spans: the SDK span has kind CLIENT, and its child, the API span, has kind SERVER and service.name = claude-platform.
Counting tokens
Anthropic puts token usage on several levels of the same request: onanthropic.messages.create and again on each anthropic.model_request under it, and on the SDK client span when you also use SDK export. The values overlap, they are not separate usage.
LangWatch currently adds up the token counts of every span in a trace. For Claude Platform traces, the trace’s token total, and the cost estimated from it, therefore counts the same tokens more than once. This will be fixed. Until then, to count each token once, add up only these spans:
- Messages API request: the
anthropic.model_requestspans, plus anyanthropic.compactionspans. - Managed Agents session: the
anthropic.model_requestandanthropic.session.outcome_evaluationspans.
gen_ai.usage.input_tokens already includes tokens read from and written to the prompt cache. Anthropic’s token usage reference lists every usage attribute.
Connect to your own app traces
Set up SDK export to nest the Claude API spans under your own spans, next to the rest of your agent: retrieval, tools, other model calls. The Claude SDK emits its spans to the global OpenTelemetry tracer provider, which the LangWatch SDK registers. The Python SDK needsanthropic 1.14.0 or later. In TypeScript, use the latest @anthropic-ai/sdk. The Claude SDK records prompts and responses only in content mode, which you turn on separately from the destination’s content mode.
traceparent header. Send both to the same LangWatch project.
You can also skip langwatch.setup() and point your own OpenTelemetry SDK at LangWatch with environment variables:
/v1/traces, because the OpenTelemetry SDK uses the traces endpoint as given.
Turn traces into evaluations and datasets
With Full content, each Claude Platform trace holds the prompt, the response and every tool call, so the rest of LangWatch works on it:- Run online evaluations on incoming traces, for example to score answer quality or catch PII.
- Add traces to a dataset and use it in experiments when you change a prompt or a model.
- Group a Managed Agents session’s turns as one conversation and add threads to datasets.
Troubleshooting
Related
- OpenTelemetry integration guide: send any OTLP traces to LangWatch.
- Anthropic Python instrumentation and Anthropic Go instrumentation.
- Anthropic’s API tracing setup, SDK tracing setup and span reference.