DOCS
Claude Agent SDK
The Claude Agent SDK exports from the agent process when telemetry is enabled. Traces are in beta and need the enhanced telemetry switch. Do not use the console exporter with the SDK. The console stream is the SDK message channel.
- Create an ingest key.
- Set the variables below on the agent options, or in the environment the process inherits.
- In TypeScript, spread the parent environment into
options.envfirst. That option replaces the inherited environment. - Run one prompt and wait until the iterator finishes so the process can flush.
- If nothing arrives, set
CLAUDE_CODE_OTEL_DIAG_STDERRto1and read stderr. Export errors are otherwise quiet.
The traces endpoint below is the base URL. The SDK appends the traces path. Protocol is HTTP protobuf, which Monitor accepts.
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1
export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=https://balerxgate.com
export OTEL_EXPORTER_OTLP_HEADERS=x-balerx-key=YOUR_INGEST_KEYPython passes the same map as ClaudeAgentOptions(env=...). TypeScript passes it as options.env after the parent environment.
Some Claude spans use attribute names that are not the GenAI names Monitor prefers. The run can still appear. Token totals are read from gen_ai.usage.input_tokens and gen_ai.usage.output_tokens when those attributes exist.
