* Send the OTLP job-setup span and propagate trace context via GITHUB_OUTPUT / * GITHUB_ENV. Non-fatal: all errors are silently swallowed. * * The trace-id is ALWAYS resolved and written to GITHUB_OUTPUT / GITHUB_ENV so * that cross-job span correlation works even when OTEL_EXPORTER_OTLP_ENDPOI
()
| 95 | * @returns {Promise<void>} |
| 96 | */ |
| 97 | async function run() { |
| 98 | const endpoints = process.env.GH_AW_OTLP_ENDPOINTS; |
| 99 | |
| 100 | const { sendJobSetupSpan, isValidTraceId, isValidSpanId } = require("./send_otlp_span.cjs"); |
| 101 | |
| 102 | const rawStartMs = process.env.SETUP_START_MS; |
| 103 | const parsedMs = /^\d+$/.test(rawStartMs ?? "") ? Number(rawStartMs) : NaN; |
| 104 | const startMs = Number.isSafeInteger(parsedMs) ? parsedMs : 0; |
| 105 | |
| 106 | // Explicitly read INPUT_TRACE_ID and pass it as options.traceId so the |
| 107 | // activation job's trace ID is used even when process.env propagation |
| 108 | // through GitHub Actions expression evaluation is unreliable. |
| 109 | const inputTraceId = getActionInput("TRACE_ID").toLowerCase(); |
| 110 | if (inputTraceId) { |
| 111 | console.log(`[otlp] INPUT_TRACE_ID=${inputTraceId} (will reuse activation trace)`); |
| 112 | } else { |
| 113 | console.log("[otlp] INPUT_TRACE_ID not set, a new trace ID will be generated"); |
| 114 | } |
| 115 | const inputParentSpanId = getActionInput("PARENT_SPAN_ID").toLowerCase(); |
| 116 | if (inputParentSpanId) { |
| 117 | console.log(`[otlp] INPUT_PARENT_SPAN_ID=${inputParentSpanId} (will parent setup span)`); |
| 118 | } |
| 119 | |
| 120 | // Normalize to the canonical underscore form so sendJobSetupSpan (which |
| 121 | // reads process.env.INPUT_JOB_NAME) always finds the value. |
| 122 | const inputJobName = getActionInput("JOB_NAME"); |
| 123 | if (inputJobName) { |
| 124 | process.env.INPUT_JOB_NAME = inputJobName; |
| 125 | } |
| 126 | if (inputParentSpanId) { |
| 127 | process.env.INPUT_PARENT_SPAN_ID = inputParentSpanId; |
| 128 | } |
| 129 | |
| 130 | const inputOTLPOIDCToken = getActionInput("OTLP_OIDC_TOKEN"); |
| 131 | if (inputOTLPOIDCToken) { |
| 132 | const existingHeaders = process.env.OTEL_EXPORTER_OTLP_HEADERS || ""; |
| 133 | const mergedHeaders = mergeAuthorizationHeader(existingHeaders, inputOTLPOIDCToken); |
| 134 | |
| 135 | process.env.OTEL_EXPORTER_OTLP_HEADERS = mergedHeaders; |
| 136 | writeEnvLine(process.env.GITHUB_ENV, "OTEL_EXPORTER_OTLP_HEADERS", mergedHeaders, "OTEL_EXPORTER_OTLP_HEADERS", "GITHUB_ENV"); |
| 137 | |
| 138 | const existingEndpoints = process.env.GH_AW_OTLP_ENDPOINTS || ""; |
| 139 | const mergedEndpoints = mergeAuthorizationIntoOTLPEndpoints(existingEndpoints, inputOTLPOIDCToken); |
| 140 | if (mergedEndpoints && mergedEndpoints !== existingEndpoints) { |
| 141 | process.env.GH_AW_OTLP_ENDPOINTS = mergedEndpoints; |
| 142 | writeEnvLine(process.env.GITHUB_ENV, "GH_AW_OTLP_ENDPOINTS", mergedEndpoints, "GH_AW_OTLP_ENDPOINTS", "GITHUB_ENV"); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | if (!endpoints) { |
| 147 | console.log("[otlp] GH_AW_OTLP_ENDPOINTS not set, skipping setup span"); |
| 148 | } else { |
| 149 | console.log(`[otlp] sending setup span to configured endpoints`); |
| 150 | } |
| 151 | |
| 152 | const { traceId, spanId, parentSpanId } = await sendJobSetupSpan({ |
| 153 | startMs, |
| 154 | traceId: inputTraceId || undefined, |
no test coverage detected