Monitoring
> ## Documentation Index > Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt > Use this file to discover all available pages before exploring further.
Overview
Documentation Index
Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt Use this file to discover all available pages before exploring further.
Monitoring
Learn how to enable and configure OpenTelemetry for Claude Code.
Track Claude Code usage, costs, and tool activity across your organization by exporting telemetry data through OpenTelemetry (OTel). Claude Code exports metrics as time series data via the standard metrics protocol, events via the logs/events protocol, and optionally distributed traces via the traces protocol. Configure your metrics, logs, and traces backends to match your monitoring requirements.
Quick start
Configure OpenTelemetry using environment variables:
# 1. Enable telemetry
# 2. Choose exporters (both are optional - configure only what you need)
# 3. Configure OTLP endpoint (for OTLP exporter)
# 4. Set authentication (if required)
# 5. For debugging: reduce export intervals
# 6. Run Claude Code
claude
The default export intervals are 60 seconds for metrics and 5 seconds for logs. During setup, you may want to use shorter intervals for debugging purposes. Remember to reset these for production use.
For full configuration options, see the OpenTelemetry specification.
Administrator configuration
Administrators can configure OpenTelemetry settings for all users through the managed settings file. This allows for centralized control of telemetry settings across an organization. See the settings precedence for more information about how settings are applied.
Example managed settings configuration:
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://collector.example.com:4317",
"OTEL_EXPORTER_OTLP_HEADERS": "Authorization=Bearer example-token"
}
}
Managed settings can be distributed via MDM (Mobile Device Management) or other device management solutions. Environment variables defined in the managed settings file have high precedence and cannot be overridden by users.
Configuration details
Common configuration variables
| Environment Variable | Description | Example Values |
|---|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | Enables telemetry collection (required) | 1 |
OTEL_METRICS_EXPORTER | Metrics exporter types, comma-separated. Use none to disable | console, otlp, prometheus, none |
OTEL_LOGS_EXPORTER | Logs/events exporter types, comma-separated. Use none to disable | console, otlp, none |
OTEL_EXPORTER_OTLP_PROTOCOL | Protocol for OTLP exporter, applies to all signals | grpc, http/json, http/protobuf |
OTEL_EXPORTER_OTLP_ENDPOINT | OTLP collector endpoint for all signals | http://localhost:4317 |
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL | Protocol for metrics, overrides general setting | grpc, http/json, http/protobuf |
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | OTLP metrics endpoint, overrides general setting | http://localhost:4318/v1/metrics |
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL | Protocol for logs, overrides general setting | grpc, http/json, http/protobuf |
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT | OTLP logs endpoint, overrides general setting | http://localhost:4318/v1/logs |
OTEL_EXPORTER_OTLP_HEADERS | Authentication headers for OTLP | Authorization=Bearer token |
OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY | Client key for mTLS authentication | Path to client key file |
OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE | Client certificate for mTLS authentication | Path to client cert file |
OTEL_METRIC_EXPORT_INTERVAL | Export interval in milliseconds (default: 60000) | 5000, 60000 |
OTEL_LOGS_EXPORT_INTERVAL | Logs export interval in milliseconds (default: 5000) | 1000, 10000 |
OTEL_LOG_USER_PROMPTS | Enable logging of user prompt content (default: disabled) | 1 to enable |
OTEL_LOG_TOOL_DETAILS | Enable logging of tool parameters and input arguments in tool events and trace span attributes: Bash commands, MCP server and tool names, skill names, and tool input. Also enables custom, plugin, and MCP command names on user_prompt events (default: disabled) | 1 to enable |
OTEL_LOG_TOOL_CONTENT | Enable logging of tool input and output content in span events (default: disabled). Requires tracing. Content is truncated at 60 KB | 1 to enable |
OTEL_LOG_RAW_API_BODIES | Emit the full Anthropic Messages API request and response JSON as api_request_body / api_response_body log events (default: disabled). Bodies include the entire conversation history. Enabling this implies consent to everything OTEL_LOG_USER_PROMPTS, OTEL_LOG_TOOL_DETAILS, and OTEL_LOG_TOOL_CONTENT would reveal | 1 for inline bodies truncated at 60 KB, or file:<dir> for untruncated bodies on disk with a body_ref pointer in the event |
OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE | Metrics temporality preference (default: delta). Set to cumulative if your backend expects cumulative temporality | delta, cumulative |
CLAUDE_CODE_OTEL_HEADERS_HELPER_DEBOUNCE_MS | Interval for refreshing dynamic headers (default: 1740000ms / 29 minutes) | 900000 |
Metrics cardinality control
The following environment variables control which attributes are included in metrics to manage cardinality:
| Environment Variable | Description | Default Value | Example to Disable |
|---|---|---|---|
OTEL_METRICS_INCLUDE_SESSION_ID | Include session.id attribute in metrics | true | false |
OTEL_METRICS_INCLUDE_VERSION | Include app.version attribute in metrics | false | true |
| `OTEL_METRICS_INCLUDE_ACCO |