Skip to content

Commit c890c53

Browse files
Copilotpelikhan
andauthored
fix: address code review feedback on send_otlp_span.cjs and test file
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/5738fc76-45bf-47ab-af6c-8de1dc9ec689 Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
1 parent 233b74c commit c890c53

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

actions/setup/index.js

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

actions/setup/js/send_otlp_span.test.cjs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ describe("sendOTLPSpan", () => {
176176
// ---------------------------------------------------------------------------
177177

178178
describe("sendJobSetupSpan", () => {
179+
/** @type {Record<string, string | undefined>} */
179180
const savedEnv = {};
180181
const envKeys = ["OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_SERVICE_NAME", "INPUT_JOB_NAME", "GH_AW_INFO_WORKFLOW_NAME", "GH_AW_INFO_ENGINE_ID", "GITHUB_RUN_ID", "GITHUB_ACTOR", "GITHUB_REPOSITORY"];
181182

@@ -198,6 +199,20 @@ describe("sendJobSetupSpan", () => {
198199
}
199200
});
200201

202+
/**
203+
* Extract the scalar value from an OTLP attribute's `value` union, covering all
204+
* known OTLP value types (stringValue, intValue, boolValue).
205+
*
206+
* @param {{ key: string, value: { stringValue?: string, intValue?: number, boolValue?: boolean } }} attr
207+
* @returns {string | number | boolean | undefined}
208+
*/
209+
function attrValue(attr) {
210+
if (attr.value.stringValue !== undefined) return attr.value.stringValue;
211+
if (attr.value.intValue !== undefined) return attr.value.intValue;
212+
if (attr.value.boolValue !== undefined) return attr.value.boolValue;
213+
return undefined;
214+
}
215+
201216
it("is a no-op when OTEL_EXPORTER_OTLP_ENDPOINT is not set", async () => {
202217
await sendJobSetupSpan();
203218
expect(fetch).not.toHaveBeenCalled();
@@ -228,7 +243,7 @@ describe("sendJobSetupSpan", () => {
228243
expect(span.traceId).toMatch(/^[0-9a-f]{32}$/);
229244
expect(span.spanId).toMatch(/^[0-9a-f]{16}$/);
230245

231-
const attrs = Object.fromEntries(span.attributes.map(a => [a.key, a.value.stringValue ?? a.value.intValue ?? a.value.boolValue]));
246+
const attrs = Object.fromEntries(span.attributes.map(a => [a.key, attrValue(a)]));
232247
expect(attrs["gh-aw.job.name"]).toBe("agent");
233248
expect(attrs["gh-aw.workflow.name"]).toBe("my-workflow");
234249
expect(attrs["gh-aw.engine.id"]).toBe("copilot");

0 commit comments

Comments
 (0)