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
5 changes: 3 additions & 2 deletions actions/setup/js/action_setup_otlp.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ async function run() {

const { sendJobSetupSpan, isValidTraceId, isValidSpanId } = require(path.join(__dirname, "send_otlp_span.cjs"));

const parsedStartMs = parseInt(process.env.SETUP_START_MS || "0", 10);
const startMs = Number.isFinite(parsedStartMs) ? parsedStartMs : 0;
const rawStartMs = process.env.SETUP_START_MS;
const parsedMs = /^\d+$/.test(rawStartMs ?? "") ? Number(rawStartMs) : NaN;
const startMs = Number.isSafeInteger(parsedMs) ? parsedMs : 0;

// Explicitly read INPUT_TRACE_ID and pass it as options.traceId so the
// activation job's trace ID is used even when process.env propagation
Expand Down
24 changes: 24 additions & 0 deletions actions/setup/js/action_setup_otlp.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,30 @@ describe("action_setup_otlp.cjs", () => {

expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 }));
});

it("should pass startMs=0 when SETUP_START_MS is a partial number string like '123abc'", async () => {
process.env.SETUP_START_MS = "123abc";

await run();

expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 }));
});

it("should pass startMs=0 when SETUP_START_MS is scientific notation like '1e3'", async () => {
process.env.SETUP_START_MS = "1e3";

await run();

expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 }));
});

it("should pass startMs=0 when SETUP_START_MS is hex notation like '0x10'", async () => {
process.env.SETUP_START_MS = "0x10";

await run();

expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 }));
});
});

describe("INPUT_TRACE_ID handling", () => {
Expand Down