Skip to content

[codex] Add token usage to turn tracing spans#19432

Merged
charley-openai merged 1 commit intomainfrom
dev/charley/turn-token-tracing
Apr 28, 2026
Merged

[codex] Add token usage to turn tracing spans#19432
charley-openai merged 1 commit intomainfrom
dev/charley/turn-token-tracing

Conversation

@charley-openai
Copy link
Copy Markdown
Contributor

@charley-openai charley-openai commented Apr 24, 2026

Why

Slow Codex turns are easier to debug when token usage is visible in the trace itself, without joining against separate analytics. This adds token usage to existing turn-handling spans for regular user turns only.

Example turn
Screenshot 2026-04-24 at 3 03 07 PM

What Changed

Added response-level token fields on completed handle_responses spans:

gen_ai.usage.input_tokens
gen_ai.usage.cache_read.input_tokens
gen_ai.usage.output_tokens
codex.usage.reasoning_output_tokens
codex.usage.total_tokens
Added aggregate token fields on regular turn spans:

codex.turn.token_usage.*
Added an explicit regular-turn opt-in via SessionTask::records_turn_token_usage_on_span() so this is not coupled to span-name strings.

Testing

  • cargo test -p codex-otel
  • cargo test -p codex-core turn_and_completed_response_spans_record_token_usage
  • just fmt
  • just fix -p codex-core
  • just fix -p codex-otel
  • Manual local Electron/app-server smoke test: regular user turn emits the new span fields

Known status: cargo test -p codex-core was attempted and failed in unrelated existing areas: config approvals, request-permissions, git-info ordering, and subagent metadata persistence.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 24, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@charley-openai charley-openai force-pushed the dev/charley/turn-token-tracing branch from b693e55 to c9b64ef Compare April 24, 2026 20:13
@charley-openai
Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 24, 2026
@charley-openai charley-openai force-pushed the dev/charley/turn-token-tracing branch from c9b64ef to f7ddddc Compare April 24, 2026 22:09
@charley-openai charley-openai marked this pull request as ready for review April 24, 2026 22:46
@charley-openai charley-openai requested a review from a team as a code owner April 24, 2026 22:46
@charley-openai charley-openai force-pushed the dev/charley/turn-token-tracing branch from f7ddddc to 12b293e Compare April 26, 2026 04:40
Copy link
Copy Markdown
Collaborator

@jif-oai jif-oai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@charley-openai charley-openai merged commit de2ccf9 into main Apr 28, 2026
25 checks passed
@charley-openai charley-openai deleted the dev/charley/turn-token-tracing branch April 28, 2026 18:41
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants