Skip to content

Telemetry

Claude Code exports all three OpenTelemetry signals from the CLI itself, and it reads the standard TRACEPARENT. A run’s Claude Code session therefore appears inside the run’s own trace, nested under the harness invocation span.

Everything here is gated on the deployment exporting telemetry. See Observability for the OTEL_EXPORTER_OTLP_ENDPOINT master switch.

SignalExportedNotes
TracesYesSpans named claude_code.interaction, claude_code.llm_request, claude_code.tool, claude_code.hook. Span names and attributes are beta and may change between Claude Code releases.
MetricsYesToken counts, cost, and session counters.
LogsYesStructured session events.

A run sets these on the container before the session:

VariableValuePurpose
CLAUDE_CODE_ENABLE_TELEMETRY1The master switch. Nothing is exported without it.
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA1Gates traces. With this unset, only metrics and logs are emitted.
OTEL_TRACES_EXPORTERotlpEach signal needs its exporter named.
OTEL_METRICS_EXPORTERotlp
OTEL_LOGS_EXPORTERotlp
OTEL_EXPORTER_OTLP_ENDPOINTthe collectorRewritten to be reachable from inside the container.
OTEL_EXPORTER_OTLP_PROTOCOLhttp/protobuf
OTEL_SERVICE_NAMEtcab-harness-claude
OTEL_RESOURCE_ATTRIBUTESthe run’s tcab.* attributesCorrelates the session to the run.
OTEL_TRACES_EXPORT_INTERVAL1000
OTEL_METRIC_EXPORT_INTERVAL1000
OTEL_LOGS_EXPORT_INTERVAL1000
TRACEPARENTthe run’s trace contextJoins the run’s trace. Set only when a trace is in scope.

Both Claude Code switches are required. CLAUDE_CODE_ENABLE_TELEMETRY alone yields metrics and logs, and the beta switch is what adds traces.

The three export intervals are shortened from their multi-second defaults. A harness session is short-lived, and the default batching drops the tail of a session when the process exits before the next flush.

Claude Code reads TRACEPARENT from its environment at session start in claude -p and Agent SDK sessions. A run always invokes claude --print, so linking always applies.

The trace context carries the sampling decision, so a run whose trace is not sampled suppresses Claude Code’s export too. TRACEPARENT is also passed to Bash subprocesses while tracing is active, so an instrumented tool the model invokes slots into the same trace.