codex exec does not export the `codex.turn.token_usage` OTLP metric (0.144.x), despite #12913 being closed
Summary
With OpenTelemetry configured via [otel] exporter = { otlp-http = {...} }, codex exec (the non-interactive CLI) exports traces and log events to the configured OTLP collector but exports no OTLP metrics - in particular the documented codex.turn.token_usage histogram is never emitted. The interactive TUI exports it. As a result, per-run token/cost usage is invisible to OTLP metric-based monitoring for any automated / CI / agent workflow that drives codex exec.
Notably, the per-turn token counts are present in the exported OTLP - but only as span/log attributes, not as a metric instrument (details below).
Environment
- codex-cli 0.144.3 (reproduced current; 0.144.4 has no user-facing changes and 0.144.5 is a dangerous-command-detection fix only - no telemetry changes, so this applies to latest)
- Linux; OTLP export via
otlp-httpto a local collector
Repro
~/.codex/config.toml:
``toml``
[otel]
environment = "dev"
exporter = { otlp-http = { endpoint = "http://127.0.0.1:4319", protocol = "binary" } }
- Run a minimal OTLP sink on
127.0.0.1:4319that records incoming POST bodies. codex exec --sandbox read-only "print OK"- Inspect the captured OTLP payloads (5 POSTs, ~11 KB).
Observed
- OTLP POSTs arrive carrying codex traces / log events:
codex.startup_phase,codex.api_request,codex.sse_event,codex.websocket_request/connect,codex.user_prompt,codex.turn_ttft,codex.conversation_starts. - Per-turn token counts are present only as span/log attributes:
input_token_count,output_token_count,cached_token_count,reasoning_token_count,tool_token_count. - The OTLP metric
codex.turn.token_usage(histogram, withtoken_type) is absent - no metric datapoints are exported undercodex execat all. - The CLI prints
tokens used Nto stdout, so the totals exist internally.
Expected
codex exec exports the codex.turn.token_usage metric (histogram, by token_type: input / cached_input / output / reasoning_output) to the configured OTLP collector, the same as the interactive TUI - so headless usage can be monitored via OTLP metrics.
Not a duplicate
- #12913 reported this and was closed via #13083 ("Enable analytics in codex exec and codex mcp-server"), which defaulted analytics-on at exec OTel init. Per the repro above, the OTLP
token_usagemetric is still not exported undercodex exec. - Distinct from #18600 (structured session metrics in exec stdout output, not OTLP) and #27467-#27469 (exec-server metrics, not the one-shot
codex execCLI).
Impact
Headless / automated codex exec usage (CI pipelines, multi-agent orchestration) cannot surface token/cost usage into OTLP metric dashboards, forcing out-of-band parsing of ~/.codex/sessions/**/rollout-*.jsonl (or scraping the log attributes) to recover per-run token counts. Emitting the already-computed counts as the documented metric would close the gap.