Surface OTel token usage from agent-stdio.log when proxy usage logs are missing#34036
Merged
Conversation
7 tasks
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
This reverts commit 48040c6. Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Improve OTel instrumentation to surface token usage from agent-stdio.log
Surface OTel token usage from agent-stdio.log when proxy usage logs are missing
May 22, 2026
pelikhan
approved these changes
May 22, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a runtime fallback so OTLP gh-aw.agent.conclusion spans still get gen_ai.usage.* token attributes when /tmp/gh-aw/agent_usage.json is missing, by extracting and normalizing usage from agent-stdio.log result events (while preserving agent_usage.json as the preferred source).
Changes:
- Extend
readAgentRuntimeMetrics()to parseresult.usagefromagent-stdio.logand normalize cache token field variants. - Prefer
/tmp/gh-aw/agent_usage.jsonwhen present; otherwise fall back to runtime metrics token usage for span enrichment. - Add tests covering fallback behavior and precedence when both sources exist.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/send_otlp_span.cjs | Adds runtime token-usage normalization + fallback path for GenAI OTLP usage enrichment. |
| actions/setup/js/send_otlp_span.test.cjs | Adds regression tests for fallback to agent-stdio.log and precedence of agent_usage.json. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Most
gh-aw.agent.conclusionspans were missinggen_ai.usage.*attributes because token enrichment depended solely on/tmp/gh-aw/agent_usage.json, which is only written when proxy token logs are present. Engines already emit equivalent usage data inagent-stdio.logresult events, but that path was not being consumed for OTel enrichment.Add runtime token-usage fallback
readAgentRuntimeMetrics()to readresult.usagefromagent-stdio.logagent_usage.jsonbehavior as the primary source when availableNormalize engine usage shapes
agent_usage.jsoncache_read_input_tokens→cache_read_tokenscache_creation_input_tokens→cache_write_tokensKeep span semantics unchanged
gen_ai.usage.total_tokensasinput + outputCover fallback and precedence
agent-stdio.logwhenagent_usage.jsonis absentagent_usage.jsonwhen both sources existExample of the runtime event now used as fallback:
{ "type": "result", "num_turns": 3, "usage": { "input_tokens": 48200, "output_tokens": 1350, "cache_read_input_tokens": 41000, "cache_creation_input_tokens": 3100 } }