diff --git a/actions/setup/js/send_otlp_span.cjs b/actions/setup/js/send_otlp_span.cjs index 9fb4dec4881..aa7c55e320a 100644 --- a/actions/setup/js/send_otlp_span.cjs +++ b/actions/setup/js/send_otlp_span.cjs @@ -5,6 +5,7 @@ const { randomBytes } = require("crypto"); const fs = require("fs"); const { nowMs } = require("./performance_now.cjs"); const { buildWorkflowRunUrl } = require("./workflow_metadata_helpers.cjs"); +const { getErrorMessage } = require("./error_helpers.cjs"); /** * send_otlp_span.cjs @@ -709,10 +710,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { const agentOutput = readJSONIfExists("/tmp/gh-aw/agent_output.json") || {}; const outputErrors = Array.isArray(agentOutput.errors) ? agentOutput.errors : []; const outputItems = Array.isArray(agentOutput.items) ? agentOutput.items : []; - const errorMessages = outputErrors - .map(e => (e && typeof e.message === "string" ? e.message : String(e))) - .filter(Boolean) - .slice(0, 5); + const errorMessages = outputErrors.map(getErrorMessage).filter(Boolean).slice(0, 5); if (isAgentFailure && errorMessages.length > 0) { statusMessage = `agent ${agentConclusion}: ${errorMessages[0]}`.slice(0, 256); @@ -755,7 +753,8 @@ async function sendJobConclusionSpan(spanName, options = {}) { attributes.push(buildAttr("gh-aw.error.messages", errorMessages.join(" | "))); } attributes.push(buildAttr("gh-aw.output.item_count", outputItems.length)); - const itemTypes = [...new Set(outputItems.map(i => (i && typeof i.type === "string" ? i.type : "")).filter(Boolean))].sort(); + const rawItemTypes = outputItems.map(i => (i && typeof i.type === "string" ? i.type : "")).filter(Boolean); + const itemTypes = [...new Set(rawItemTypes)].sort(); if (itemTypes.length > 0) { attributes.push(buildAttr("gh-aw.output.item_types", itemTypes.join(","))); } @@ -810,7 +809,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { } const errorTimeNano = toNanoString(eventTimeMs); return outputErrors - .map(e => (e && typeof e.message === "string" ? e.message : String(e))) + .map(getErrorMessage) .filter(Boolean) .map(msg => { // Extract colon-prefixed type when available ("push_to_pull_request_branch:...")