fix: add env-var fallbacks for gh-aw.workflow.name in conclusion spans#26320
fix: add env-var fallbacks for gh-aw.workflow.name in conclusion spans#26320
Conversation
#1088) Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a17346bf-8708-478f-b2cf-77ba64d49dd3 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR ensures sendJobConclusionSpan populates gh-aw.workflow.name even when aw_info.json is missing (e.g., jobs failing before the agent runs), by adding environment-variable fallbacks so conclusion spans remain discoverable in workflow-name–filtered dashboards.
Changes:
- Add a fallback chain for
workflowNameinsendJobConclusionSpan:aw_info.json→GH_AW_INFO_WORKFLOW_NAME→GITHUB_WORKFLOW→"". - Extend
sendJobConclusionSpantests with new cases covering each tier of the fallback chain. - Update test env cleanup to include
GH_AW_INFO_WORKFLOW_NAMEandGITHUB_WORKFLOW.
Show a summary per file
| File | Description |
|---|---|
| actions/setup/js/send_otlp_span.cjs | Adds env-var fallbacks for gh-aw.workflow.name in conclusion spans. |
| actions/setup/js/send_otlp_span.test.cjs | Adds/updates tests and env cleanup to validate the new fallback behavior. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
actions/setup/js/send_otlp_span.test.cjs:1637
- Similarly, this test assumes
aw_info.jsonis absent but doesn’t stub filesystem reads. To keep the test hermetic, stubfs.readFileSyncto throw ENOENT (or reuse a shared stub) so the fallback toGITHUB_WORKFLOWis deterministic.
it("falls back to GITHUB_WORKFLOW when aw_info.json and GH_AW_INFO_WORKFLOW_NAME are absent", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
process.env.GITHUB_WORKFLOW = "github-workflow";
await sendJobConclusionSpan("gh-aw.job.conclusion");
actions/setup/js/send_otlp_span.test.cjs:1651
- This test expects
gh-aw.workflow.nameto be empty when all sources are absent, but it still may read a real/tmp/gh-aw/aw_info.jsonif present. Stubfs.readFileSyncto throw ENOENT here (or set up a default stub for the whole describe) so the test doesn’t depend on the host filesystem state.
it("sets gh-aw.workflow.name to empty string when all sources are absent", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
await sendJobConclusionSpan("gh-aw.job.conclusion");
- Files reviewed: 2/2 changed files
- Comments generated: 2
| @@ -681,7 +681,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { | |||
| const rawParentSpanId = (process.env.GITHUB_AW_OTEL_PARENT_SPAN_ID || "").trim().toLowerCase(); | |||
| const parentSpanId = isValidSpanId(rawParentSpanId) ? rawParentSpanId : ""; | |||
|
|
|||
There was a problem hiding this comment.
sendJobConclusionSpan now resolves workflowName from GH_AW_INFO_WORKFLOW_NAME and GITHUB_WORKFLOW as fallbacks. The function’s JSDoc “Environment variables consumed” list should be updated to include these variables so the documentation matches the implementation.
| // Resolve workflowName from aw_info first, then fall back to the environment | |
| // variables GH_AW_INFO_WORKFLOW_NAME and GITHUB_WORKFLOW. |
| it("falls back to GH_AW_INFO_WORKFLOW_NAME when aw_info.json is absent", async () => { | ||
| const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" }); | ||
| vi.stubGlobal("fetch", mockFetch); | ||
|
|
||
| process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com"; | ||
| process.env.GH_AW_INFO_WORKFLOW_NAME = "env-workflow"; | ||
| process.env.GITHUB_WORKFLOW = "github-workflow"; | ||
|
|
||
| await sendJobConclusionSpan("gh-aw.job.conclusion"); | ||
|
|
There was a problem hiding this comment.
This test asserts behavior "when aw_info.json is absent" but doesn’t stub fs.readFileSync/readJSONIfExists to force that condition. If /tmp/gh-aw/aw_info.json exists on the machine running tests, the test will read it and may fail. Consider stubbing fs.readFileSync to throw ENOENT (or adding a default readFileSync stub in beforeEach for this describe) and overriding it only in tests that need file contents.
This issue also appears in the following locations of the same file:
- line 1629
- line 1644
🧪 Test Quality Sentinel ReportTest Quality Score: 90/100✅ Excellent test quality
Test Classification Details
Flagged Tests — Requires ReviewNone. All 4 tests are behavioral design tests with no issues requiring remediation. Test Inflation NoteThe test-to-production line ratio is 71:1 (71 lines added in tests vs. 1 line in production), which mechanically triggers the inflation penalty (−10 pts). However, this is well-justified: the single production line encodes a 3-tier priority chain ( Language SupportTests analyzed:
Verdict
📖 Understanding Test ClassificationsDesign Tests (High Value) verify what the system does:
Implementation Tests (Low Value) verify how the system does it:
Goal: Shift toward tests that describe the system's behavioral contract — the promises it makes to its users and collaborators.
|
sendJobConclusionSpanresolvedworkflowNameexclusively fromaw_info.json, which is only written by the agent step. Jobs that fail before the agent runs (or non-agent jobs like safe-outputs and activation) emit conclusion spans withgh-aw.workflow.name: "", making them invisible in any dashboard filtering by workflow name — exactly the failure signals that matter most for MTTR.Changes
send_otlp_span.cjs— mirror the three-layer fallback already used bysendJobSetupSpan:GH_AW_INFO_WORKFLOW_NAMEis compiler-injected at job level and is always present in the post-step runner environment where conclusion spans are sent.send_otlp_span.test.cjs— addGH_AW_INFO_WORKFLOW_NAMEandGITHUB_WORKFLOWto the env cleanup list forsendJobConclusionSpantests, and add four new tests covering each tier of the fallback chain:aw_info.json→GH_AW_INFO_WORKFLOW_NAME→GITHUB_WORKFLOW→"".