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
3 changes: 3 additions & 0 deletions actions/setup/js/send_otlp_span.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ async function sendJobConclusionSpan(spanName, options = {}) {
const workflowName = awInfo.workflow_name || "";
const engineId = awInfo.engine_id || "";
const model = awInfo.model || "";
const staged = awInfo.staged === true;
const jobName = process.env.INPUT_JOB_NAME || "";
const runId = process.env.GITHUB_RUN_ID || "";
const runAttempt = awInfo.run_attempt || process.env.GITHUB_RUN_ATTEMPT || "1";
Expand Down Expand Up @@ -594,6 +595,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));
attributes.push(buildAttr("gh-aw.staged", staged));
if (!isNaN(effectiveTokens) && effectiveTokens > 0) {
attributes.push(buildAttr("gh-aw.effective_tokens", effectiveTokens));
}
Expand Down Expand Up @@ -633,6 +635,7 @@ async function sendJobConclusionSpan(spanName, options = {}) {
if (eventName) {
resourceAttributes.push(buildAttr("github.event_name", eventName));
}
resourceAttributes.push(buildAttr("deployment.environment", staged ? "staging" : "production"));

const payload = buildOTLPPayload({
traceId,
Expand Down
82 changes: 82 additions & 0 deletions actions/setup/js/send_otlp_span.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,4 +1616,86 @@ describe("sendJobConclusionSpan", () => {
expect(keys).not.toContain("gh-aw.github.rate_limit.remaining");
});
});

describe("staged / deployment.environment", () => {
let readFileSpy;

beforeEach(() => {
readFileSpy = vi.spyOn(fs, "readFileSync").mockImplementation(() => {
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
});
});

afterEach(() => {
readFileSpy.mockRestore();
});

it("sets gh-aw.staged=false and deployment.environment=production when staged 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 stagedAttr = span.attributes.find(a => a.key === "gh-aw.staged");
expect(stagedAttr).toBeDefined();
expect(stagedAttr.value.boolValue).toBe(false);

const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "deployment.environment", value: { stringValue: "production" } });
});

it("sets gh-aw.staged=true and deployment.environment=staging when awInfo.staged=true", 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";

readFileSpy.mockImplementation(filePath => {
if (filePath === "/tmp/gh-aw/aw_info.json") {
return JSON.stringify({ staged: true });
}
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
});

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 stagedAttr = span.attributes.find(a => a.key === "gh-aw.staged");
expect(stagedAttr).toBeDefined();
expect(stagedAttr.value.boolValue).toBe(true);

const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "deployment.environment", value: { stringValue: "staging" } });
});

it("sets gh-aw.staged=false and deployment.environment=production when awInfo.staged=false", 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";

readFileSpy.mockImplementation(filePath => {
if (filePath === "/tmp/gh-aw/aw_info.json") {
return JSON.stringify({ staged: false });
}
throw Object.assign(new Error("ENOENT"), { code: "ENOENT" });
});

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 stagedAttr = span.attributes.find(a => a.key === "gh-aw.staged");
expect(stagedAttr).toBeDefined();
expect(stagedAttr.value.boolValue).toBe(false);

const resourceAttrs = body.resourceSpans[0].resource.attributes;
expect(resourceAttrs).toContainEqual({ key: "deployment.environment", value: { stringValue: "production" } });
});
});
});
Loading