[BUG] BETA_TRACING_ENDPOINT ignores OTEL_EXPORTER_OTLP_PROTOCOL: headless sessions (desktop app, claude -p) silently drop all events and traces
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet (related: #82629, #35105)
- [x] This is a single bug report
- [x] I am using the latest version of Claude Code
What's Wrong?
With ENABLE_BETA_TRACING_DETAILED=1 and BETA_TRACING_ENDPOINT set, non-interactive sessions (Claude desktop app, claude -p, SDK / stream-json) export metrics but no events (logs) and no traces. Interactive terminal sessions with the same settings export all three normally.
The beta path replaces the logs and traces exporters with OTLP/HTTP (protobuf) exporters posting to ${BETA_TRACING_ENDPOINT}/v1/logs and /v1/traces, and ignores OTEL_EXPORTER_OTLP_PROTOCOL. If BETA_TRACING_ENDPOINT is the same gRPC endpoint as OTEL_EXPORTER_OTLP_ENDPOINT (a natural choice, e.g. http://localhost:4317), every events/traces export fails. Only metrics, which stay on the regular gRPC exporter, get through.
The failure is silent. Nothing is shown unless you run with --debug-file, and the collector reports no refused records because nothing valid arrives. In our case, every Claude desktop session disappeared from an events-based dashboard, while CLI sessions kept working.
In non-interactive mode the beta path is on whenever both variables are set. In interactive mode it is also behind a feature gate/allowlist (see #82629), which is why the two modes behave differently with identical settings.
What Should Happen?
One of:
- the beta exporters honour
OTEL_EXPORTER_OTLP_PROTOCOL(or a dedicatedBETA_TRACING_PROTOCOL); - the docs state that
BETA_TRACING_ENDPOINTmust be an OTLP/HTTP endpoint (e.g.:4318, not:4317); - export failures are surfaced (a warning), rather than only in
--debug-file.
Error Messages/Logs
[ERROR] [3P telemetry] OTEL diag error: {"message":"Parse Error: Expected HTTP/, RTSP/ or ICE/","code":"HPE_INVALID_CONSTANT","reason":"Expected HTTP/, RTSP/ or ICE/","rawPacket": "\^@\^@\^F\^D\^@..."}
(The raw packet is an HTTP/2 SETTINGS frame from the gRPC port answering an HTTP/1.1 request. Seen 3x per run in --debug-file; no getOtlpLogExporters line is logged on this path.)
Steps to Reproduce
- Run an OTLP collector with gRPC on
:4317and HTTP on:4318(e.g.grafana/otel-lgtm). ~/.claude/settings.json:
``json``
{
"env": {
"CLAUDE_CODE_ENABLE_TELEMETRY": "1",
"OTEL_METRICS_EXPORTER": "otlp",
"OTEL_LOGS_EXPORTER": "otlp",
"OTEL_TRACES_EXPORTER": "otlp",
"OTEL_EXPORTER_OTLP_PROTOCOL": "grpc",
"OTEL_EXPORTER_OTLP_ENDPOINT": "http://localhost:4317",
"ENABLE_BETA_TRACING_DETAILED": "1",
"BETA_TRACING_ENDPOINT": "http://localhost:4317"
}
}
- Run headless, keeping stdin open ~25 s so the log batch can flush before exit:
``sh``
( echo '{"type":"user","message":{"role":"user","content":"reply with just: ok"}}'; sleep 25 ) \
| claude -p --input-format stream-json --output-format stream-json --verbose --debug-file d.log
- Result: metrics arrive, 0 log records and 0 spans arrive, and
d.loghas theHPE_INVALID_CONSTANTerrors above (reproduced 3/3, on 2.1.281 and 2.1.283). - Change only
BETA_TRACING_ENDPOINTtohttp://localhost:4318: events and traces arrive (24 events + 1 trace, 2/2 runs). - Or disable the beta path with
--settings '{"env":{"ENABLE_BETA_TRACING_DETAILED":"","BETA_TRACING_ENDPOINT":""}}': events arrive over gRPC (getOtlpLogExporters: types=["otlp"], protocol=grpc…First logs export: SUCCESS).
Note for anyone reproducing: unsetting the variables in the shell (env -u) is not enough, because the env block in settings.json re-applies them inside the process.
Claude Model
Not model-specific.
Is this a regression?
I don't know
Claude Code Version
2.1.283 (CLI) and 2.1.281 (bundled with Claude desktop 2.9939.2)
Platform
Claude subscription (Team)
Operating System
macOS (27.0.0, arm64)
Terminal/Shell
Claude desktop app (headless Claude Code), and claude -p from Terminal.app / zsh
Additional Information
- Related: #82629 (these variables are undocumented; the expected format of
BETA_TRACING_ENDPOINTis unstated) and #35105 (OTel not exported in pipe/stream-json mode; possibly the same root cause if those users had the beta flags set). - Workaround: set
BETA_TRACING_ENDPOINTto the collector's OTLP/HTTP endpoint (http://localhost:4318).