C

Claude Code

Instrument Claude Code with its built-in OpenTelemetry export. Token usage, cost, sessions, and tool activity — no SDK, just environment variables.

Built by

telemetry.dev

Language

Any

Transport

OTLP/HTTP

Category

Coding agents

About the Claude Code integration

Claude Code ships with OpenTelemetry instrumentation built in. Set a few environment variables and it exports metrics — token usage, cost, session counts, lines of code, commits — plus structured log events for API requests, tool executions, and permission decisions straight to https://ingest.telemetry.dev over OTLP/HTTP. No SDK, no collector, no code changes.

Key features

  • Zero-code setup: Telemetry is enabled entirely through environment variables; nothing to install or wrap.
  • Token and cost metrics: claude_code.token.usage and claude_code.cost.usage arrive as time series, ready for dashboards and spend alerts.
  • Session and productivity metrics: Session counts, active time, lines of code changed, and commits created per developer or CI job.
  • Structured events: API requests, tool results, and permission decisions land as log events for audit trails and per-session debugging.
  • Privacy by default: Prompts and tool arguments are redacted unless you opt in with OTEL_LOG_USER_PROMPTS=1.

Get started

  1. Create a telemetry.dev project API key.

  2. Set the telemetry environment variables before launching Claude Code — in your shell profile, or in managed-settings.json for a whole team:

    export CLAUDE_CODE_ENABLE_TELEMETRY=1
    export OTEL_METRICS_EXPORTER=otlp
    export OTEL_LOGS_EXPORTER=otlp
    export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
    export OTEL_EXPORTER_OTLP_ENDPOINT="https://ingest.telemetry.dev"
    export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer%20$TELEMETRY_DEV_API_KEY"
    export OTEL_RESOURCE_ATTRIBUTES="deployment.environment.name=production"
  3. Run claude. Metrics flush every 60 seconds and events every 5 seconds; token usage, cost, and tool activity appear in telemetry.dev grouped by model and session.

Environment variables must be set before Claude Code starts — exporting them in an already-running session has no effect. For faster feedback while testing, set OTEL_METRIC_EXPORT_INTERVAL=10000.