Use the ingesting host from your source
Copy the ingesting host exactly as shown for your source. It already points to your team's data region, so your metrics and logs land in the right place.
Claude Code exports its own usage data over OpenTelemetry: metrics for sessions, tokens, and cost, structured events for prompts, tool calls, and API errors, and optional traces for individual interactions. Point that export at Better Stack to see how your team uses Claude Code, what it costs, and where it fails, with no extra instrumentation.
You need Claude Code installed and authenticated, and a Better Stack Telemetry source to receive the data.
Create one in Telemetry β Sources β Connect source, or read more in the Quick start guide. Select the OpenTelemetry platform, then copy the source token and ingesting host shown for the source.
Copy the ingesting host exactly as shown for your source. It already points to your team's data region, so your metrics and logs land in the right place.
There are two ways to send the data. Use the settings file to keep telemetry on across sessions, or shell variables to turn it on for a single terminal session. Either way, replace $INGESTING_HOST and $SOURCE_TOKEN with the values from your source.
Add the variables to your Claude Code settings file. ~/.claude/settings.json applies to every project, while a project's .claude/settings.json applies to that project and can be committed to source control.
Export the variables in your shell before starting Claude Code. They apply only to that terminal session.
Better Stack ingests OpenTelemetry over HTTP, so with the http/protobuf protocol Claude Code appends the per-signal paths /v1/metrics and /v1/logs to the endpoint for you.
Claude Code reads telemetry configuration only at startup, so restart it after any change.
Start Claude Code:
At the prompt, give it a small task so it exercises the model and a tool. For example:
Approve the action when Claude Code asks. This one task produces a claude_code.user_prompt, one or more claude_code.api_request events, a claude_code.tool_decision and claude_code.tool_result for the file it writes and runs, and a claude_code.assistant_response.
Open Live tail in Better Stack. Within a minute you should see those claude_code.* events.
Run claude --debug and look for OpenTelemetry export errors. Check that the ingesting host and source token match your source, and remember that Claude Code reads telemetry configuration only at startup.
Claude Code emits these metrics, each attributable by user, team, and model:
claude_code.session.count: sessions startedclaude_code.cost.usage: estimated spend in USDclaude_code.token.usage: tokens used, with a type label of input, output, cacheCreation, or cacheReadclaude_code.lines_of_code.count: lines added or removedclaude_code.commit.count: git commits createdclaude_code.pull_request.count: pull requests openedclaude_code.code_edit_tool.decision: edit permission decisions, with a decision label of accept or rejectclaude_code.active_time.total: active time in secondsFor the full list of metrics, events, and attributes, see the Claude Code monitoring documentation.
Claude Code redacts prompt text and tool details by default. To include them, add these variables to the env block:
These variables send prompt text, commands, file paths, and other potentially sensitive content to your source. Enable them only where that is acceptable.
Claude Code can also export distributed traces that link each prompt to the API requests and tool executions it triggers. This capability is currently in beta. To turn it on, add "CLAUDE_CODE_ENHANCED_TELEMETRY_BETA": "1" and "OTEL_TRACES_EXPORTER": "otlp" to the same env block. Traces reach Better Stack at the same endpoint. See Tracing for how to explore them.
Please let us know at hello@betterstack.com.
We're happy to help! π
We use cookies to authenticate users, improve the product user experience, and for personalized ads. Learn more.