openai / openai/codex

OTel response.completed reports total token usage as tool_token_count

Open
#40,208 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug CLI rate-limits
Dominant language
Rust
Stars
125k
Forks
19.4k
PR merge metrics
PR metrics pending

Description

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?
  1. Inspect codex-rs/otel/src/events/session_telemetry.rs on current main.
  2. Trace usage.total_tokens back to TokenUsage.total_tokens, populated from the provider's completed-response usage.
  3. Observe that the value is emitted as tool_token_count.
  4. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with codex-rs/otel/src/events/session_telemetry.rs at the response.completed emission and trace usage.total_tokens to its provider usage source. Then read codex-rs/core/tests/suite/otel.rs around the existing expectation. Confirm the intended compatibility approach for the attribute name, and update the emission and test or documentation so the value's semantics are unambiguous.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.