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
1 change: 1 addition & 0 deletions actions/setup/js/send_otlp_span.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,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("gen_ai.request.model", model));
if (eventName) attributes.push(buildAttr("gh-aw.event_name", eventName));
// Deployment state: prefer the env var (set from github.event.deployment_status.state
// in the compiled workflow), fall back to aw_info.deployment_state or aw_context propagation.
Expand Down
38 changes: 38 additions & 0 deletions actions/setup/js/send_otlp_span.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,44 @@ describe("sendJobConclusionSpan", () => {
expect(keys).not.toContain("gen_ai.workflow.name");
});

it("includes gen_ai.request.model on the conclusion span when model is set in aw_info.json", 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";

const readFileSpy = vi.spyOn(fs, "readFileSync").mockImplementation(filePath => {
if (filePath === "/tmp/gh-aw/aw_info.json") {
return JSON.stringify({ model: "claude-3-5-sonnet-20241022", engine_id: "claude" });
}
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
});

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

const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
expect(span.name).toBe("gh-aw.job.conclusion");
const attrs = Object.fromEntries(span.attributes.map(a => [a.key, a.value.stringValue ?? a.value.intValue]));
expect(attrs["gen_ai.request.model"]).toBe("claude-3-5-sonnet-20241022");
});

it("omits gen_ai.request.model from the conclusion span when model is absent in aw_info.json", 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");

Comment on lines +1906 to +1907
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

This test relies on the real filesystem state for /tmp/gh-aw/aw_info.json. If that file happens to exist on a developer machine (or is created by another test/process), the test can become flaky because sendJobConclusionSpan will read it and may include gen_ai.request.model. To make the test hermetic, stub fs.readFileSync for /tmp/gh-aw/aw_info.json to throw ENOENT (or return JSON without a model) and restore the spy afterward, consistent with the surrounding tests.

Suggested change
await sendJobConclusionSpan("gh-aw.job.conclusion");
const readFileSpy = vi.spyOn(fs, "readFileSync").mockImplementation(filePath => {
if (filePath === "/tmp/gh-aw/aw_info.json") {
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
}
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
});
try {
await sendJobConclusionSpan("gh-aw.job.conclusion");
} finally {
readFileSpy.mockRestore();
}

Copilot uses AI. Check for mistakes.
const body = JSON.parse(mockFetch.mock.calls[0][1].body);
const span = body.resourceSpans[0].scopeSpans[0].spans[0];
expect(span.name).toBe("gh-aw.job.conclusion");
const keys = span.attributes.map(a => a.key);
expect(keys).not.toContain("gen_ai.request.model");
});

it("includes gh-aw.run.attempt attribute from GITHUB_RUN_ATTEMPT env var", async () => {
const mockFetch = vi.fn().mockResolvedValue({ ok: true, status: 200, statusText: "OK" });
vi.stubGlobal("fetch", mockFetch);
Expand Down
Loading