Observability for Claude Agent SDK with Opik
Claude Code telemetry is configured through environment variables.
When this guide applies
Use this guide when you want to configure Claude Code’s official OpenTelemetry settings and align endpoint/header values with your Opik deployment mode.
Opik ingests OTel trace spans. Claude Code emits spans when you set
CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1 and OTEL_TRACES_EXPORTER=otlp.
Prompt, tool I/O, and assistant output are redacted by default and are only captured on
spans once you enable the content flags and the detailed-tracing beta below.
Opik OTLP endpoint modes
For full endpoint/header details, see Opik OpenTelemetry overview.
Opik Cloud
Enterprise deployment
Self-hosted instance
Required headers:
AuthorizationComet-Workspace
Optional headers:
projectName(recommended for deterministic routing)
Minimal setup for full trace visibility
This is the minimal set of environment variables that captures the user prompt, tool
input/output, and assistant output as spans in Opik (Opik Cloud shown; swap the endpoint for
your deployment mode above). Set these before starting your Claude Agent SDK app, or claude -p
(non-interactive) runs.
Assistant output (block 4) relies on the detailed-tracing beta, which is only ungated for the
Claude Agent SDK and non-interactive claude -p. In an interactive claude session that beta
is gated, so you will get the user prompt and tool I/O but not response.model_output.
Why each block matters
- Blocks 1-2 get
claude_code.*spans into Opik. WithoutCLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1Claude Code emits only metrics/logs (no spans), and nothing appears in Opik. - Block 3 un-redacts the user prompt and tool input/output, which are redacted by default.
- Block 4 is required for assistant/AI output. Claude Code only puts response text on spans (
response.model_output) under the detailed-tracing beta; otherwise it goes to the OTel logs signal, which Opik does not ingest.BETA_TRACING_ENDPOINTis a standard OTLP base URL — point it at the same Opik endpoint. Its exporter reusesOTEL_EXPORTER_OTLP_HEADERS(block 2), so theAuthorization/Comet-Workspaceheaders Opik Cloud and Enterprise require are sent automatically; no separate header variable is needed. For the Claude Agent SDK and other non-interactive (claude -p) runs, this beta needs no additional server-side enablement.
OTEL_LOG_ASSISTANT_RESPONSES=1 also un-redacts response text, but on the OTel logs signal — which Opik has no receiver for. Use block 4 (detailed-tracing beta) to get assistant output into Opik.
Validation
- Start your Claude Agent SDK app (or
claude -p) with the variables above set. - Open the target project in Opik and find the
claude_code.interactiontrace. - Confirm the spans carry content: the user prompt (trace input),
tool_input/ tool output onclaude_code.toolspans, andresponse.model_outputonclaude_code.llm_requestspans.