diff --git a/actions/setup/js/send_otlp_span.cjs b/actions/setup/js/send_otlp_span.cjs index 8c077000c2..c70c04891a 100644 --- a/actions/setup/js/send_otlp_span.cjs +++ b/actions/setup/js/send_otlp_span.cjs @@ -496,6 +496,9 @@ async function sendJobSetupSpan(options = {}) { if (engineId) { attributes.push(buildAttr("gh-aw.engine.id", engineId)); } + if (eventName) { + attributes.push(buildAttr("gh-aw.event_name", eventName)); + } const resourceAttributes = [buildAttr("github.repository", repository), buildAttr("github.run_id", runId)]; if (repository && runId) { @@ -707,6 +710,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { if (jobName) attributes.push(buildAttr("gh-aw.job.name", jobName)); if (engineId) attributes.push(buildAttr("gh-aw.engine.id", engineId)); if (model) attributes.push(buildAttr("gh-aw.model", model)); + if (eventName) attributes.push(buildAttr("gh-aw.event_name", eventName)); attributes.push(buildAttr("gh-aw.staged", staged)); if (!isNaN(effectiveTokens) && effectiveTokens > 0) { attributes.push(buildAttr("gh-aw.effective_tokens", effectiveTokens)); diff --git a/actions/setup/js/send_otlp_span.test.cjs b/actions/setup/js/send_otlp_span.test.cjs index 3b7505ce47..c2b47aed9b 100644 --- a/actions/setup/js/send_otlp_span.test.cjs +++ b/actions/setup/js/send_otlp_span.test.cjs @@ -1047,6 +1047,34 @@ describe("sendJobSetupSpan", () => { expect(resourceKeys).not.toContain("github.event_name"); }); + it("includes gh-aw.event_name as span attribute when GITHUB_EVENT_NAME is set", 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_EVENT_NAME = "workflow_dispatch"; + + await sendJobSetupSpan(); + + const body = JSON.parse(mockFetch.mock.calls[0][1].body); + const span = body.resourceSpans[0].scopeSpans[0].spans[0]; + expect(span.attributes).toContainEqual({ key: "gh-aw.event_name", value: { stringValue: "workflow_dispatch" } }); + }); + + it("omits gh-aw.event_name span attribute when GITHUB_EVENT_NAME is not set", 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 sendJobSetupSpan(); + + const body = JSON.parse(mockFetch.mock.calls[0][1].body); + const span = body.resourceSpans[0].scopeSpans[0].spans[0]; + const keys = span.attributes.map(a => a.key); + expect(keys).not.toContain("gh-aw.event_name"); + }); + it("includes github.ref as resource attribute when GITHUB_REF is set", async () => { const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" }); vi.stubGlobal("fetch", mockFetch); @@ -1578,6 +1606,34 @@ describe("sendJobConclusionSpan", () => { expect(resourceKeys).not.toContain("github.event_name"); }); + it("includes gh-aw.event_name as span attribute when GITHUB_EVENT_NAME is set", 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_EVENT_NAME = "pull_request"; + + await sendJobConclusionSpan("gh-aw.job.conclusion"); + + const body = JSON.parse(mockFetch.mock.calls[0][1].body); + const span = body.resourceSpans[0].scopeSpans[0].spans[0]; + expect(span.attributes).toContainEqual({ key: "gh-aw.event_name", value: { stringValue: "pull_request" } }); + }); + + it("omits gh-aw.event_name span attribute when GITHUB_EVENT_NAME is not set", 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"); + + const body = JSON.parse(mockFetch.mock.calls[0][1].body); + const span = body.resourceSpans[0].scopeSpans[0].spans[0]; + const keys = span.attributes.map(a => a.key); + expect(keys).not.toContain("gh-aw.event_name"); + }); + it("includes github.ref as resource attribute when GITHUB_REF is set", async () => { const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" }); vi.stubGlobal("fetch", mockFetch);