Monitor Claude Code with Axiom
Configure Claude Code to send OpenTelemetry metrics and logs to Axiom for usage monitoring and observability.
Claude Code has built-in OpenTelemetry support that exports metrics and logs. Axiom natively ingests OTLP data, making the two a natural fit. This guide covers the Axiom-specific configuration to connect Claude Code telemetry to Axiom.
Prerequisites
- Create an Axiom account.
- Create two datasets in Axiom: one for metrics and one for logs. Claude Code doesn't emit traces. For more information, see Create dataset.
- Create an API token in Axiom with ingest permissions for both datasets.
How Axiom routes OpenTelemetry data
Axiom routes data to datasets via headers, and the header differs by signal type:
- Logs use
x-axiom-dataset - Metrics use
x-axiom-metrics-dataset
This means signal-specific header configuration is required rather than a single shared OTEL_EXPORTER_OTLP_HEADERS value.
The /v1/metrics endpoint only supports the application/x-protobuf content type.
Configure environment variables
Create a file named setup-otel.sh with the following content:
Verify the integration
Run the following command in your terminal:
Use Claude Code for 15 to 20 seconds to generate telemetry data. Ask questions, run commands, or perform any typical tasks.
In Axiom, go to your datasets and observe the telemetry data:
- The logs dataset shows events like
claude_code.user_prompt,claude_code.tool_result, andclaude_code.api_request. - The metrics dataset shows counters like
claude_code.session.countandclaude_code.token.usage, updating on the 10-second interval configured above.
Production considerations
When moving from testing to production, consider these adjustments:
-
Disable prompt logging: Remove
OTEL_LOG_USER_PROMPTS=1unless prompt content is needed in your observability backend. This reduces the volume of sensitive data stored. -
Use managed settings for teams: For team deployments, administrators can set these variables in Claude Code's managed settings file instead of relying on each developer to source a script.
-
Add resource attributes: Use
OTEL_RESOURCE_ATTRIBUTESto tag all telemetry with department, team, or cost center identifiers for filtering and alerting in Axiom.shell -
Adjust export intervals: For production, consider using longer intervals to reduce overhead:
shell
Reference
Environment variables
| Variable | Description |
|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | Set to 1 to enable OpenTelemetry export. |
OTEL_METRICS_EXPORTER | Set to otlp to enable OTLP metrics export. |
OTEL_LOGS_EXPORTER | Set to otlp to enable OTLP logs export. |
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL | Protocol for metrics. Use http/protobuf for Axiom. |
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL | Protocol for logs. Use http/protobuf for Axiom. |
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | Axiom metrics endpoint URL. |
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT | Axiom logs endpoint URL. |
OTEL_EXPORTER_OTLP_METRICS_HEADERS | Headers for metrics including authorization and dataset. |
OTEL_EXPORTER_OTLP_LOGS_HEADERS | Headers for logs including authorization and dataset. |
OTEL_METRIC_EXPORT_INTERVAL | Metrics export interval in milliseconds. Default: 60000. |
OTEL_LOGS_EXPORT_INTERVAL | Logs export interval in milliseconds. Default: 5000. |
OTEL_LOG_USER_PROMPTS | Set to 1 to log full prompt content. |
OTEL_LOG_TOOL_DETAILS | Set to 1 to log tool and MCP details. |
OTEL_RESOURCE_ATTRIBUTES | Comma-separated key=value pairs for resource attributes. |
Expected telemetry data
Claude Code exports the following telemetry:
Logs:
claude_code.user_prompt: User prompts sent to Claude Code.claude_code.tool_result: Results from tool executions.claude_code.api_request: API requests made by Claude Code.
Metrics:
claude_code.session.count: Number of Claude Code sessions.claude_code.token.usage: Token usage counters.