Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion actions/setup/js/send_otlp_span.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,25 @@ function parseBooleanEnv(value) {
return undefined;
}

/**
* Resolve the job name for conclusion spans.
*
* Normally this comes from INPUT_JOB_NAME (job-name action input), but some
* deployment paths can miss that env var in the post step. In that case, fall
* back to parsing the conclusion span name ("gh-aw.<job>.conclusion").
*
* @param {string} spanName
* @returns {string}
*/
function resolveConclusionJobName(spanName) {
const inputJobName = (process.env.INPUT_JOB_NAME || "").trim();
if (inputJobName) {
return inputJobName;
}
const match = /^gh-aw\.([^.]+)\.conclusion$/.exec(spanName);
return match ? match[1] : "";
}

/**
* Parse setup-time aw_context passed via environment before aw_info.json exists.
*
Expand Down Expand Up @@ -1937,7 +1956,7 @@ async function sendJobConclusionSpan(spanName, options = {}) {
const awmgVersion = (typeof awInfo.awmg_version === "string" ? awInfo.awmg_version : "") || process.env.GH_AW_INFO_AWMG_VERSION || "";
const bodyModified = typeof awInfo.body_modified === "boolean" ? awInfo.body_modified : parseBooleanEnv(process.env.GH_AW_INFO_BODY_MODIFIED);
const trackerId = process.env.GH_AW_TRACKER_ID || awInfo.tracker_id || "";
const jobName = process.env.INPUT_JOB_NAME || "";
const jobName = resolveConclusionJobName(spanName);
const jobEmitsOwnTokenUsage = jobName === "agent" || jobName === "detection" || (!!engineId && jobName === engineId);
const runId = process.env.GITHUB_RUN_ID || "";
const runAttempt = awInfo.run_attempt || process.env.GITHUB_RUN_ATTEMPT || "1";
Expand Down
17 changes: 17 additions & 0 deletions actions/setup/js/send_otlp_span.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3561,6 +3561,23 @@ describe("sendJobConclusionSpan", () => {
expect(aicAttr.value.doubleValue).toBe(0.125);
});

it("includes gh-aw.aic when INPUT_JOB_NAME is missing but span name is gh-aw.agent.conclusion", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);

process.env.GH_AW_OTLP_ENDPOINTS = JSON.stringify([{ url: "https://traces.example.com" }]);
process.env.GH_AW_AIC = "0.125";
delete process.env.INPUT_JOB_NAME;

await sendJobConclusionSpan("gh-aw.agent.conclusion");

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
const aicAttr = span.attributes.find(a => a.key === "gh-aw.aic");
expect(aicAttr).toBeDefined();
expect(aicAttr.value.doubleValue).toBe(0.125);
});

it("emits dashboard metrics and aliases on the conclusion span", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down
Loading