@@ -176,6 +176,7 @@ describe("sendOTLPSpan", () => {
176176// ---------------------------------------------------------------------------
177177
178178describe ( "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 - 9 a - f ] { 32 } $ / ) ;
229244 expect ( span . spanId ) . toMatch ( / ^ [ 0 - 9 a - 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