{"version":"2.0.18","anchor":"opentelemetry-tracing-support-opt-in","canonical_anchor":"opentelemetry-tracing-support-opt-in","heading":"OpenTelemetry Tracing Support (Opt-In)","tier":null,"area":null,"scope":null,"heads_up":null,"url":"https:\/\/changelogs.core-directive.com\/v\/2.0.18\/e\/opentelemetry-tracing-support-opt-in","release_url":"https:\/\/changelogs.core-directive.com\/v\/2.0.18","markdown":"### OpenTelemetry Tracing Support (Opt-In)\n\n**What:** Comprehensive distributed tracing infrastructure for monitoring Claude Code's internal operations, API calls, and performance metrics. This feature is **disabled by default** and requires explicit opt-in.\n\n**How to use:**\n\n`# Enable telemetry export CLAUDE_CODE_ENABLE_TELEMETRY=true # Configure where traces are exported (optional) export OTEL_TRACES_EXPORTER=console # or \"otlp\" for OpenTelemetry collectors # Privacy controls (optional - both default to redacted) export OTEL_LOG_USER_PROMPTS=true # Log user prompts in traces export OTEL_LOG_MODEL_RESPONSE=true # Log model responses in traces` **Details:**\n\n- Tracks user interactions, LLM API requests\/responses, and tool executions\n- **Privacy-conscious by default**: User prompts and model responses are redacted unless explicitly enabled via `OTEL_LOG_USER_PROMPTS` and `OTEL_LOG_MODEL_RESPONSE`\n- Supports multiple export formats:\n- `console` - Output traces to console for debugging\n- `otlp` - Export to OpenTelemetry Protocol collectors (supports gRPC, HTTP\/JSON, HTTP\/Protobuf)\n- Records detailed metrics: token counts (input, output, cache read, cache creation), latency, success\/failure rates\n- Full OpenTelemetry specification compliance with 15+ configuration environment variables\n- Configurable sampling strategies via `OTEL_TRACES_SAMPLER` (defaults to `parentbased_always_on`)\n- Batch span processor with tunable performance parameters\n- **Evidence**: `DiB() at line 2314`, `JiB() at line 2048`, `Jb0() at line 2087`, `cL5() at line 2277`\n\n**Supported Environment Variables:**\n\n*Telemetry Control:*\n\n- `CLAUDE_CODE_ENABLE_TELEMETRY` - Master switch (default: disabled)\n- `OTEL_LOG_USER_PROMPTS` - Include user prompts in traces (default: redacted)\n- `OTEL_LOG_MODEL_RESPONSE` - Include model responses in traces (default: redacted)\n\n*Export Configuration:*\n\n- `OTEL_TRACES_EXPORTER` - Exporters: \"console\", \"otlp\" (comma-separated)\n- `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` - Protocol: \"grpc\", \"http\/json\", \"http\/protobuf\"\n- `OTEL_EXPORTER_OTLP_PROTOCOL` - Default protocol for all signals\n\n*Sampling:*\n\n- `OTEL_TRACES_SAMPLER` - Sampler type (default: \"parentbased_always_on\")\n- `OTEL_TRACES_SAMPLER_ARG` - Sampler configuration (e.g., ratio for TraceIdRatioBased)\n\n*Span Limits:*\n\n- `OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT` - Max attribute value length (unlimited by default)\n- `OTEL_ATTRIBUTE_COUNT_LIMIT` - Max attributes per span (default: 128)\n- `OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT` - Span-specific attribute value limit\n- `OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT` - Span-specific attribute count (default: 128)\n- `OTEL_SPAN_LINK_COUNT_LIMIT` - Max links per span (default: 128)\n- `OTEL_SPAN_EVENT_COUNT_LIMIT` - Max events per span (default: 128)\n- `OTEL_SPAN_ATTRIBUTE_PER_EVENT_COUNT_LIMIT` - Max attributes per event (default: 128)\n- `OTEL_SPAN_ATTRIBUTE_PER_LINK_COUNT_LIMIT` - Max attributes per link (default: 128)\n\n*Batch Processor:*\n\n- `OTEL_BSP_MAX_EXPORT_BATCH_SIZE` - Batch size (default: 512)\n- `OTEL_BSP_MAX_QUEUE_SIZE` - Queue size (default: 2048)\n- `OTEL_BSP_SCHEDULE_DELAY` - Export delay in ms (default: 5000)\n- `OTEL_BSP_EXPORT_TIMEOUT` - Timeout in ms (default: 30000)"}