OTel response.completed reports total token usage as tool_token_count
What version of Codex CLI is running?
codex-cli 0.149.0-alpha.4.1
What subscription do you have?
ChatGPT Pro ($200/month)
Which model were you using?
gpt-5.6-sol
What platform is your computer?
Darwin 25.5.0 arm64 arm (macOS 26.5.2)
What terminal emulator and version are you using (if applicable)?
Not applicable (source-level issue)
Codex doctor report
Not run (source-level issue)
What issue are you seeing?
The response.completed OpenTelemetry event exports TokenUsage.total_tokens under the attribute tool_token_count:
tool_token_count = %usage.total_tokens
TokenUsage.total_tokens comes directly from the provider's response.completed.response.usage.total_tokens. It represents total token usage, not tool-specific token usage.
This is an OpenTelemetry attribute naming/semantic mismatch, not a token calculation error. Downstream consumers can interpret the same value as either total tokens or tool tokens.
What steps can reproduce the bug?
- Inspect
codex-rs/otel/src/events/session_telemetry.rson currentmain. - Trace
usage.total_tokensback toTokenUsage.total_tokens, populated from the provider's completed-response usage. - Observe that the value is emitted as
tool_token_count. - See the existing OTel test expecting the same attribute.
Current source:
What is the expected behavior?
The OpenTelemetry attribute name should match the value's semantics. Total usage should be exposed as a total-token attribute, or the historical field should be explicitly documented with a compatibility and migration plan.
Additional information
Related but not duplicate: #33668 reports a missing codex.turn.token_usage metric.
External consumers already handle this field inconsistently: Statewright maps it to total_tokens, while ax and ai-observer treat it as tool tokens.
The naming mismatch was introduced with #2103 and remains present on current main.
1 Comment
Proposed one-line fix (external PRs are currently limited to collaborators on this repository, so posting the change here for maintainers)
The mismatch is in
codex-rs/otel/src/events/session_telemetry.rs, insse_event_completed:TokenUsage(defined incodex-rs/protocol/src/protocol.rs) has no tool-token field — it only carriesinput_tokens,cached_input_tokens,cache_write_input_tokens,output_tokens,reasoning_output_tokens, andtotal_tokens. Sotool_token_countwas mislabeled with the total-token value. Renaming the attribute tototal_token_countmakes the emitted semantics match the value it carries.tool_token_countappears nowhere else in the repository and no tests or snapshots depend on it, so this single-line change is self-contained.The change is ready on
fangyuanbutinghua/codex:fix/otel-total-token-count(commit49655e9) if a maintainer would like to apply or cherry-pick it.