Skip to content

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.

  1. Create an ingest key.
  2. Set the variables below on the agent options, or in the environment the process inherits.
  3. In TypeScript, spread the parent environment into options.env first. That option replaces the inherited environment.
  4. Run one prompt and wait until the iterator finishes so the process can flush.
  5. If nothing arrives, set CLAUDE_CODE_OTEL_DIAG_STDERR to 1 and 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_KEY

Python 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.