Learn how to enable and configure OpenTelemetry for Claude Code.
/Library/Application Support/ClaudeCode/managed-settings.json
/etc/claude-code/managed-settings.json
C:\ProgramData\ClaudeCode\managed-settings.json
Environment Variable | Description | Example Values |
---|---|---|
CLAUDE_CODE_ENABLE_TELEMETRY | Enables telemetry collection (required) | 1 |
OTEL_METRICS_EXPORTER | Metrics exporter type(s) (comma-separated) | console , otlp , prometheus |
OTEL_LOGS_EXPORTER | Logs/events exporter type(s) (comma-separated) | console , otlp |
OTEL_EXPORTER_OTLP_PROTOCOL | Protocol for OTLP exporter (all signals) | grpc , http/json , http/protobuf |
OTEL_EXPORTER_OTLP_ENDPOINT | OTLP collector endpoint (all signals) | http://localhost:4317 |
OTEL_EXPORTER_OTLP_METRICS_PROTOCOL | Protocol for metrics (overrides general) | grpc , http/json , http/protobuf |
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT | OTLP metrics endpoint (overrides general) | http://localhost:4318/v1/metrics |
OTEL_EXPORTER_OTLP_LOGS_PROTOCOL | Protocol for logs (overrides general) | grpc , http/json , http/protobuf |
OTEL_EXPORTER_OTLP_LOGS_ENDPOINT | OTLP logs endpoint (overrides general) | 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 |
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_ACCOUNT_UUID | Include user.account_uuid attribute in metrics | true | false |
.claude/settings.json
:
OTEL_RESOURCE_ATTRIBUTES
environment variable:
OTEL_RESOURCE_ATTRIBUTES
environment variable follows the W3C Baggage specification, which has strict formatting requirements:user.organizationName=My Company
is invalidkey1=value1,key2=value2
"key=value with spaces"
) is not supported by the OpenTelemetry specification and will result in attributes being prefixed with quotes.Attribute | Description | Controlled By |
---|---|---|
session.id | Unique session identifier | OTEL_METRICS_INCLUDE_SESSION_ID (default: true) |
app.version | Current Claude Code version | OTEL_METRICS_INCLUDE_VERSION (default: false) |
organization.id | Organization UUID (when authenticated) | Always included when available |
user.account_uuid | Account UUID (when authenticated) | OTEL_METRICS_INCLUDE_ACCOUNT_UUID (default: true) |
terminal.type | Terminal type (e.g., iTerm.app , vscode , cursor , tmux ) | Always included when detected |
Metric Name | Description | Unit |
---|---|---|
claude_code.session.count | Count of CLI sessions started | count |
claude_code.lines_of_code.count | Count of lines of code modified | count |
claude_code.pull_request.count | Number of pull requests created | count |
claude_code.commit.count | Number of git commits created | count |
claude_code.cost.usage | Cost of the Claude Code session | USD |
claude_code.token.usage | Number of tokens used | tokens |
claude_code.code_edit_tool.decision | Count of code editing tool permission decisions | count |
claude_code.active_time.total | Total active time in seconds | s |
type
: ("added"
, "removed"
)model
: Model identifier (e.g., “claude-3-5-sonnet-20241022”)type
: ("input"
, "output"
, "cacheRead"
, "cacheCreation"
)model
: Model identifier (e.g., “claude-3-5-sonnet-20241022”)tool
: Tool name ("Edit"
, "MultiEdit"
, "Write"
, "NotebookEdit"
)decision
: User decision ("accept"
, "reject"
)language
: Programming language of the edited file (e.g., "TypeScript"
, "Python"
, "JavaScript"
, "Markdown"
). Returns "unknown"
for unrecognized file extensions.OTEL_LOGS_EXPORTER
is configured):
claude_code.user_prompt
Attributes:
event.name
: "user_prompt"
event.timestamp
: ISO 8601 timestampprompt_length
: Length of the promptprompt
: Prompt content (redacted by default, enable with OTEL_LOG_USER_PROMPTS=1
)claude_code.tool_result
Attributes:
event.name
: "tool_result"
event.timestamp
: ISO 8601 timestamptool_name
: Name of the toolsuccess
: "true"
or "false"
duration_ms
: Execution time in millisecondserror
: Error message (if failed)decision
: Either "accept"
or "reject"
source
: Decision source - "config"
, "user_permanent"
, "user_temporary"
, "user_abort"
, or "user_reject"
tool_parameters
: JSON string containing tool-specific parameters (when available)
bash_command
, full_command
, timeout
, description
, sandbox
claude_code.api_request
Attributes:
event.name
: "api_request"
event.timestamp
: ISO 8601 timestampmodel
: Model used (e.g., “claude-3-5-sonnet-20241022”)cost_usd
: Estimated cost in USDduration_ms
: Request duration in millisecondsinput_tokens
: Number of input tokensoutput_tokens
: Number of output tokenscache_read_tokens
: Number of tokens read from cachecache_creation_tokens
: Number of tokens used for cache creationclaude_code.api_error
Attributes:
event.name
: "api_error"
event.timestamp
: ISO 8601 timestampmodel
: Model used (e.g., “claude-3-5-sonnet-20241022”)error
: Error messagestatus_code
: HTTP status code (if applicable)duration_ms
: Request duration in millisecondsattempt
: Attempt number (for retried requests)claude_code.tool_decision
Attributes:
event.name
: "tool_decision"
event.timestamp
: ISO 8601 timestamptool_name
: Name of the tool (e.g., “Read”, “Edit”, “MultiEdit”, “Write”, “NotebookEdit”, etc.)decision
: Either "accept"
or "reject"
source
: Decision source - "config"
, "user_permanent"
, "user_temporary"
, "user_abort"
, or "user_reject"
Metric | Analysis Opportunity |
---|---|
claude_code.token.usage | Break down by type (input/output), user, team, or model |
claude_code.session.count | Track adoption and engagement over time |
claude_code.lines_of_code.count | Measure productivity by tracking code additions/removals |
claude_code.commit.count & claude_code.pull_request.count | Understand impact on development workflows |
claude_code.cost.usage
metric helps with:
user.account_uuid
, organization.id
, session.id
, model
, and app.version
.
service.name
: claude-code
service.version
: Current Claude Code versionos.type
: Operating system type (e.g., linux
, darwin
, windows
)os.version
: Operating system version stringhost.arch
: Host architecture (e.g., amd64
, arm64
)wsl.version
: WSL version number (only present when running on Windows Subsystem for Linux)com.anthropic.claude_code
OTEL_LOG_USER_PROMPTS=1