claude-code - 💡(How to fix) Fix [BUG] OpenTelemetry not emitting in non-interactive (-p) mode [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#46338Fetched 2026-04-11 06:22:54
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
commented ×2labeled ×2closed ×1

Code Example

# This emits nothing to OTel:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=otlp \
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
OTEL_SERVICE_NAME=test-agent \
claude -p "say hello"

# Even console exporter produces no output:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=console \
OTEL_LOGS_EXPORTER=console \
OTEL_METRIC_EXPORT_INTERVAL=1000 \
OTEL_LOGS_EXPORT_INTERVAL=1000 \
claude -p "say hello"
RAW_BUFFERClick to expand / collapse

Bug Description

Claude Code does not emit any OpenTelemetry data (metrics, logs, or traces) when running in non-interactive -p mode. Interactive mode works correctly with the same configuration.

Steps to Reproduce

# This emits nothing to OTel:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=otlp \
OTEL_LOGS_EXPORTER=otlp \
OTEL_EXPORTER_OTLP_PROTOCOL=grpc \
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 \
OTEL_SERVICE_NAME=test-agent \
claude -p "say hello"

# Even console exporter produces no output:
CLAUDE_CODE_ENABLE_TELEMETRY=1 \
OTEL_METRICS_EXPORTER=console \
OTEL_LOGS_EXPORTER=console \
OTEL_METRIC_EXPORT_INTERVAL=1000 \
OTEL_LOGS_EXPORT_INTERVAL=1000 \
claude -p "say hello"

Expected Behavior

OTel data should be exported in -p mode, same as interactive mode. At minimum, the claude_code.session.count, claude_code.token.usage, claude_code.cost.usage metrics and claude_code.user_prompt, claude_code.api_request, claude_code.tool_result events should fire.

Actual Behavior

Zero OTel output in -p mode. No metrics, no logs/events, no traces. The console exporter produces nothing. The same configuration works perfectly in interactive mode.

Impact

This blocks OTel observability for any automation using claude -p, including:

  • CI/CD pipelines
  • Agent runtimes (K8s Jobs running claude -p for automated tasks)
  • Batch processing scripts

Environment

  • Version: 2.1.100
  • Platform: macOS (darwin) + Linux (K8s container, node:22-bookworm)
  • Verified with both gRPC (port 4317) and HTTP/protobuf (port 4318)
  • Collector confirmed reachable from the container (curl returns 405)
  • Interactive mode works with identical env vars on same machine

extent analysis

TL;DR

The issue can be mitigated by investigating the differences in how Claude Code handles telemetry in interactive versus non-interactive modes.

Guidance

  • Review the Claude Code documentation and source code to understand how the -p mode differs from interactive mode in terms of telemetry initialization and export.
  • Verify that the CLAUDE_CODE_ENABLE_TELEMETRY environment variable is being correctly set and recognized in non-interactive mode.
  • Test the claude -p command with a simplified configuration, such as only enabling metrics or logs, to isolate which type of telemetry is failing to export.
  • Consider adding debug logging or tracing to the Claude Code application to gain insight into the telemetry export process in non-interactive mode.

Example

No code example is provided due to the lack of specific implementation details in the issue.

Notes

The root cause of the issue is uncertain, but it appears to be related to how Claude Code handles telemetry in non-interactive mode. Further investigation is needed to determine the exact cause and develop a fix.

Recommendation

Apply a workaround by modifying the automation scripts to use interactive mode or by developing a custom solution to export telemetry data from non-interactive mode, as upgrading to a fixed version is not mentioned in the issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING