From 2337556381ddefa8de3e4bed6d7108712738b4a1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 21 Apr 2026 06:25:16 +0000 Subject: [PATCH 1/2] refactor(otlp): extract errorToString helper and simplify itemTypes - Extract duplicate error-to-string conversion logic into a named errorToString() helper function, replacing two identical inline lambdas in sendJobConclusionSpan and buildSpanEvents - Split the complex itemTypes one-liner into rawItemTypes + itemTypes for better step-by-step readability Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- actions/setup/js/send_otlp_span.cjs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/actions/setup/js/send_otlp_span.cjs b/actions/setup/js/send_otlp_span.cjs index 9fb4dec4881..7815017196c 100644 --- a/actions/setup/js/send_otlp_span.cjs +++ b/actions/setup/js/send_otlp_span.cjs @@ -70,6 +70,17 @@ function buildAttr(key, value) { return { key, value: { stringValue: String(value) } }; } +/** + * Convert an error entry from agent_output.json to a plain string message. + * Handles both structured error objects (with a `message` field) and raw values. + * + * @param {unknown} e + * @returns {string} + */ +function errorToString(e) { + return e && typeof e.message === "string" ? e.message : String(e); +} + // --------------------------------------------------------------------------- // OTLP SpanKind constants // --------------------------------------------------------------------------- @@ -709,10 +720,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(errorToString).filter(Boolean).slice(0, 5); if (isAgentFailure && errorMessages.length > 0) { statusMessage = `agent ${agentConclusion}: ${errorMessages[0]}`.slice(0, 256); @@ -755,7 +763,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 +819,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { } const errorTimeNano = toNanoString(eventTimeMs); return outputErrors - .map(e => (e && typeof e.message === "string" ? e.message : String(e))) + .map(errorToString) .filter(Boolean) .map(msg => { // Extract colon-prefixed type when available ("push_to_pull_request_branch:...") From e51a3e3f6453dead4fb9db529398e616d778d9b9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:39:54 +0000 Subject: [PATCH 2/2] refactor(otlp): use shared getErrorMessage helper in send_otlp_span Agent-Logs-Url: https://github.com/github/gh-aw/sessions/eba8c7e4-15be-41f6-8314-0a7ce376458c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- actions/setup/js/send_otlp_span.cjs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/actions/setup/js/send_otlp_span.cjs b/actions/setup/js/send_otlp_span.cjs index 7815017196c..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 @@ -70,17 +71,6 @@ function buildAttr(key, value) { return { key, value: { stringValue: String(value) } }; } -/** - * Convert an error entry from agent_output.json to a plain string message. - * Handles both structured error objects (with a `message` field) and raw values. - * - * @param {unknown} e - * @returns {string} - */ -function errorToString(e) { - return e && typeof e.message === "string" ? e.message : String(e); -} - // --------------------------------------------------------------------------- // OTLP SpanKind constants // --------------------------------------------------------------------------- @@ -720,7 +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(errorToString).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); @@ -819,7 +809,7 @@ async function sendJobConclusionSpan(spanName, options = {}) { } const errorTimeNano = toNanoString(eventTimeMs); return outputErrors - .map(errorToString) + .map(getErrorMessage) .filter(Boolean) .map(msg => { // Extract colon-prefixed type when available ("push_to_pull_request_branch:...")