fix: usage tracking for engine jobs in sendJobConclusionSpan#38353
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes token-usage telemetry attribution for “engine jobs” in sendJobConclusionSpan by treating jobs whose INPUT_JOB_NAME matches the resolved engine ID (e.g., copilot) as the rightful emitter of gen_ai.usage.* and gh-aw.aic attributes, preventing downstream jobs from double-emitting usage data.
Changes:
- Extend
jobEmitsOwnTokenUsageto include engine jobs wherejobName === engineId. - Clarify comments around why token usage and AI credit attributes must be gated.
- Add a unit test asserting that an engine job emits token breakdown + cost attributes when job name matches engine ID.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/send_otlp_span.cjs | Updates token-usage ownership logic to include engine jobs and keeps usage emission gated to avoid downstream double-counting. |
| actions/setup/js/send_otlp_span.test.cjs | Adds coverage verifying engine-job spans emit gen_ai.usage.* and gh-aw.aic when INPUT_JOB_NAME matches the engine ID. |
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
|
✅ smoke-ci: safeoutputs CLI comment + comment-memory run (27275233892)
|
Comment MemoryNote This comment is managed by comment memory.It stores persistent context for this thread in the code block at the top of this comment.
|
fix: usage tracking for engine jobs in sendJobConclusionSpan
Summary
Fixes a gap in OTLP token-usage and AI-credit reporting where custom-engine jobs were silently skipped.
jobEmitsOwnTokenUsagepreviously did not recognise jobs whose name is the engine ID itself, so those jobs never emitted token-breakdown orgh-aw.aicattributes in their conclusion spans.What changed
actions/setup/js/send_otlp_span.cjsjobEmitsOwnTokenUsageto also match jobs whoseINPUT_JOB_NAMEequalsGH_AW_INFO_ENGINE_ID; updates two associated comments to reflect the broader matching scope.actions/setup/js/send_otlp_span.test.cjssendJobConclusionSpancorrectly emits token-breakdown andgh-aw.aiccost attributes.Why
Custom-engine jobs set
INPUT_JOB_NAMEto the engine ID. Without the additional equality check,jobEmitsOwnTokenUsagereturnedfalsefor those jobs, suppressing their usage spans entirely. This caused gaps in per-job cost and token telemetry for engine-named jobs.How
The
jobEmitsOwnTokenUsagepredicate is broadened with an|| jobName === engineIdbranch. No change to the span schema itself; token-breakdown and AI-credit attributes were already supported — they just weren't being attached.Risk
Low. The change is additive (new match branch, not a replacement). The new test provides direct coverage. No breaking changes to the OTLP span format or downstream consumers.