Skip to content
Closed
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: 11 additions & 5 deletions actions/setup/js/action_setup_otlp.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,23 @@ async function run() {
const githubOutput = process.env.GITHUB_OUTPUT;
const githubEnv = process.env.GITHUB_ENV;

/**
* @param {string | undefined} filePath
* @param {(value: string) => boolean} isValid
*/
const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => isValid(value) && writeEnvLine(filePath, key, value, logLabel, fileLabel);

// Always expose trace ID as a step output for cross-job correlation, even
// when OTLP is not configured. This ensures needs.*.outputs.setup-trace-id
// is populated for downstream jobs regardless of observability configuration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

L179-189: yagni: 11-line helper (6 params + 8-line JSDoc) replacing 5 near-identical one-line if calls. Diff grew from 5 to 18 lines for the "dedup". Keep the plain if (isValidX(v)) writeEnvLine(...) lines, or shrink the helper to a 1-line arrow fn without the JSDoc.

if (isValidTraceId(traceId)) writeEnvLine(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT");
if (isValidSpanId(spanId)) writeEnvLine(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT");
if (isValidSpanId(parentSpanId)) writeEnvLine(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT");
writeIfValid(githubOutput, "trace-id", traceId, `trace-id=${traceId}`, "GITHUB_OUTPUT", isValidTraceId);
writeIfValid(githubOutput, "span-id", spanId, `span-id=${spanId}`, "GITHUB_OUTPUT", isValidSpanId);
writeIfValid(githubOutput, "parent-span-id", parentSpanId, `parent-span-id=${parentSpanId}`, "GITHUB_OUTPUT", isValidSpanId);

// Always propagate trace/span context to subsequent steps in this job so
// that the conclusion span can find the same trace ID.
if (isValidTraceId(traceId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV");
if (isValidSpanId(spanId)) writeEnvLine(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV");
writeIfValid(githubEnv, "GITHUB_AW_OTEL_TRACE_ID", traceId, "GITHUB_AW_OTEL_TRACE_ID", "GITHUB_ENV", isValidTraceId);
writeIfValid(githubEnv, "GITHUB_AW_OTEL_PARENT_SPAN_ID", spanId, "GITHUB_AW_OTEL_PARENT_SPAN_ID", "GITHUB_ENV", isValidSpanId);
// Propagate setup-end timestamp so the conclusion span can measure actual
// job execution duration (setup-end → conclusion-start).
if (githubEnv) {
Expand Down