Claude Code
Add OTEL environment variables to your Claude Code settings to ship session telemetry — prompts, tool calls, and model API requests with token counts — to Sazabi.
About
Ship Claude Code session telemetry to Sazabi using Claude Code's built-in OTLP exporter. Once configured, every session emits structured events covering user prompts, tool calls, tool results, and model API requests with token counts and cost — no code changes to your projects required.
Events include attributes like claude_code.user_prompt, claude_code.tool_result, and claude_code.api_request, along with prompt, model, session.id, user.email, token counts, and cost per API call.
Enabling OTEL_LOG_USER_PROMPTS=1 exports raw prompt text, including any
sensitive content typed during sessions. Keep this off unless you understand
the privacy implications for your team.
Prerequisites
- Claude Code CLI installed and running
- Your Sazabi intake URL, shown above — open the log source and copy the Intake URL from its setup screen (the public key is embedded in the URL)
Set up in the dashboard
Add OTEL environment variables to Claude Code settings
Open or create ~/.claude/settings.json and add the following variables to the env block:
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "http/protobuf",
"OTEL_EXPORTER_OTLP_ENDPOINT": "<your intake URL>",
"OTEL_LOG_USER_PROMPTS": "0",
"OTEL_LOG_ASSISTANT_RESPONSES": "0"
}
}Replace <your intake URL> with the intake URL shown above.
Leave OTEL_LOG_ASSISTANT_RESPONSES at 0 — when it is unset, it falls back to the prompts setting, so enabling prompts alone would also export model responses. Do not set a metrics exporter; Claude Code metrics are not ingested.
Restart Claude Code
Claude Code loads settings at startup. Quit and relaunch Claude Code for the new environment variables to take effect.
Set up with the CLI
You can also register the Claude Code log source with the Sazabi CLI (installed and authenticated — see CLI reference).
Registering the source mints the same intake URL the dashboard shows above (the public key is embedded in its hostname):
sazabi log-sources create claude_code --mode connectionlessThe command prints the intake URL for the new source — copy the whole URL and point your sender at it using the configuration shown above. Run sazabi log-sources get <log-source-id> at any time to reprint the endpoint, or sazabi log-sources list to see every log source in the project.
Verify
Start a Claude Code session and run a prompt. Open the Intake page in the Sazabi dashboard and confirm events from the Claude Code source appear within a minute or two.
Start a thread and search for claude_code.api_request to find model API requests with token counts and cost, or search for session.id to view all events from a single session.
Troubleshooting
No events after restarting — Confirm ~/.claude/settings.json is valid JSON and the env block is correctly nested. Claude Code silently ignores settings files that fail to parse.
Events appear but prompts are missing — Confirm OTEL_LOG_USER_PROMPTS is enabled, then restart Claude Code. Prompt text is exported starting with the next session; a session that predates the setting will not include it. If privacy is a concern, set it to 0 — session structure and API metadata are still exported.
Claude Code metrics are not stored — Only the OTLP logs exporter is supported. Metric events from Claude Code are not ingested by this source.