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
16 changes: 16 additions & 0 deletions actions/setup/js/send_otlp_span.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ async function sendJobSetupSpan(options = {}) {
const actor = process.env.GITHUB_ACTOR || "";
const repository = process.env.GITHUB_REPOSITORY || "";
const eventName = process.env.GITHUB_EVENT_NAME || "";
const ref = process.env.GITHUB_REF || "";
const sha = process.env.GITHUB_SHA || "";
Comment on lines 389 to +393

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc for sendJobSetupSpan lists “Environment variables consumed” but doesn’t include the newly read GITHUB_REF/GITHUB_SHA (and also omits some other env vars used in this function). Please update the doc block so it accurately reflects the env vars this span depends on.

Copilot uses AI. Check for mistakes.

const attributes = [
buildAttr("gh-aw.job.name", jobName),
Expand All @@ -411,6 +413,12 @@ async function sendJobSetupSpan(options = {}) {
if (eventName) {
resourceAttributes.push(buildAttr("github.event_name", eventName));
}
if (ref) {
resourceAttributes.push(buildAttr("github.ref", ref));
}
if (sha) {
resourceAttributes.push(buildAttr("github.sha", sha));
}
resourceAttributes.push(buildAttr("deployment.environment", staged ? "staging" : "production"));

const payload = buildOTLPPayload({
Expand Down Expand Up @@ -568,6 +576,8 @@ async function sendJobConclusionSpan(spanName, options = {}) {
const actor = process.env.GITHUB_ACTOR || "";
const repository = process.env.GITHUB_REPOSITORY || "";
const eventName = process.env.GITHUB_EVENT_NAME || "";
const ref = process.env.GITHUB_REF || "";
const sha = process.env.GITHUB_SHA || "";
Comment on lines 576 to +580

Copilot AI Apr 5, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sendJobConclusionSpan JSDoc “Environment variables consumed” list should be updated to include GITHUB_REF/GITHUB_SHA now that these values are read and exported as resource attributes.

Copilot uses AI. Check for mistakes.

// Agent conclusion is passed to downstream jobs via GH_AW_AGENT_CONCLUSION.
// Values: "success", "failure", "timed_out", "cancelled", "skipped".
Expand Down Expand Up @@ -637,6 +647,12 @@ async function sendJobConclusionSpan(spanName, options = {}) {
if (eventName) {
resourceAttributes.push(buildAttr("github.event_name", eventName));
}
if (ref) {
resourceAttributes.push(buildAttr("github.ref", ref));
}
if (sha) {
resourceAttributes.push(buildAttr("github.sha", sha));
}
resourceAttributes.push(buildAttr("deployment.environment", staged ? "staging" : "production"));

const payload = buildOTLPPayload({
Expand Down
116 changes: 116 additions & 0 deletions actions/setup/js/send_otlp_span.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,8 @@ describe("sendJobSetupSpan", () => {
"GITHUB_ACTOR",
"GITHUB_REPOSITORY",
"GITHUB_EVENT_NAME",
"GITHUB_REF",
"GITHUB_SHA",
"GH_AW_INFO_VERSION",
];
let mkdirSpy, appendSpy;
Expand Down Expand Up @@ -931,6 +933,62 @@ describe("sendJobSetupSpan", () => {
expect(resourceKeys).not.toContain("github.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);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
process.env.GITHUB_REF = "refs/heads/main";

await sendJobSetupSpan();

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "github.ref", value: { stringValue: "refs/heads/main" } });
});

it("omits github.ref resource attribute when GITHUB_REF 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 resourceAttrs = body.resourceSpans[0].resource.attributes;
const resourceKeys = resourceAttrs.map(a => a.key);
expect(resourceKeys).not.toContain("github.ref");
});

it("includes github.sha as resource attribute when GITHUB_SHA 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_SHA = "abc1234567890def";

await sendJobSetupSpan();

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "github.sha", value: { stringValue: "abc1234567890def" } });
});

it("omits github.sha resource attribute when GITHUB_SHA 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 resourceAttrs = body.resourceSpans[0].resource.attributes;
const resourceKeys = resourceAttrs.map(a => a.key);
expect(resourceKeys).not.toContain("github.sha");
});

it("includes github.actions.run_url as resource attribute when repository and run_id are set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down Expand Up @@ -1100,6 +1158,8 @@ describe("sendJobConclusionSpan", () => {
"GITHUB_ACTOR",
"GITHUB_REPOSITORY",
"GITHUB_EVENT_NAME",
"GITHUB_REF",
"GITHUB_SHA",
"INPUT_JOB_NAME",
"GH_AW_AGENT_CONCLUSION",
];
Expand Down Expand Up @@ -1324,6 +1384,62 @@ describe("sendJobConclusionSpan", () => {
expect(resourceKeys).not.toContain("github.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);

process.env.OTEL_EXPORTER_OTLP_ENDPOINT = "https://traces.example.com";
process.env.GITHUB_REF = "refs/heads/main";

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

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "github.ref", value: { stringValue: "refs/heads/main" } });
});

it("omits github.ref resource attribute when GITHUB_REF 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 resourceAttrs = body.resourceSpans[0].resource.attributes;
const resourceKeys = resourceAttrs.map(a => a.key);
expect(resourceKeys).not.toContain("github.ref");
});

it("includes github.sha as resource attribute when GITHUB_SHA 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_SHA = "abc1234567890def";

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

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "github.sha", value: { stringValue: "abc1234567890def" } });
});

it("omits github.sha resource attribute when GITHUB_SHA 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 resourceAttrs = body.resourceSpans[0].resource.attributes;
const resourceKeys = resourceAttrs.map(a => a.key);
expect(resourceKeys).not.toContain("github.sha");
});

it("includes github.actions.run_url as resource attribute when repository and run_id are set", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down
Loading