Skip to content

fix(observability): capture Claude usage for phase events#790

Merged
j5ik2o merged 2 commits into
codex/otel-usage-events-exporter-docsfrom
codex/fix-claude-headless-usage-events
Jun 8, 2026
Merged

fix(observability): capture Claude usage for phase events#790
j5ik2o merged 2 commits into
codex/otel-usage-events-exporter-docsfrom
codex/fix-claude-headless-usage-events

Conversation

@j5ik2o

@j5ik2o j5ik2o commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Capture usage from Claude Code CLI stream-json result events and pass it through providerUsage.
  • Share Claude usage normalization between the Claude SDK provider and Claude headless provider.
  • Mark Claude SDK responses with incomplete required token fields as usageMissing instead of producing partial usage.

Context

This is stacked on #785 (codex/otel-usage-events-exporter-docs). During local verification, provider: claude emitted phase usage events with usage_missing=true even though Claude Code CLI returned token usage in the stream-json result event. The headless parser was not propagating that usage into the agent response.

Verification

  • npm test -- --run src/__tests__/claude-headless-stream-json.test.ts src/__tests__/claude-headless-client.test.ts src/__tests__/claude-executor-structured-output.test.ts
  • npm run build
  • npm run lint
  • Local --provider claude workflow after build emitted usage_missing=false phase usage events with token totals.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3bedfc5d-a048-46f0-8d79-35acf9aafa7b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-claude-headless-usage-events

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@j5ik2o j5ik2o marked this pull request as ready for review June 8, 2026 06:11
@j5ik2o j5ik2o merged commit 811b3a7 into codex/otel-usage-events-exporter-docs Jun 8, 2026
1 check passed
@j5ik2o j5ik2o deleted the codex/fix-claude-headless-usage-events branch June 8, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant