Skip to content
Closed
Changes from 1 commit
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
23 changes: 18 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,30 @@ async function run() {
const githubOutput = process.env.GITHUB_OUTPUT;
const githubEnv = process.env.GITHUB_ENV;

/**
* Write a key=value line to filePath only if isValid(value) holds.
* @param {string | undefined} filePath
* @param {string} key
* @param {string} value
* @param {string} logLabel - Label used in the confirmation log message
* @param {string} fileLabel
* @param {(value: string) => boolean} isValid
*/
const writeIfValid = (filePath, key, value, logLabel, fileLabel, isValid) => {

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.

[/codebase-design] The JSDoc types value as string, but environment variables (process.env.*) are string | undefined. The helper already passes value straight to writeEnvLine after the guard, so the practical risk is low — but the type annotation is misleading.

💡 Suggested fix

Change the @param annotation:

 * `@param` {string | undefined} value

This makes it clear to future readers why the isValid guard is necessary.

@copilot please address this.

if (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
Loading