Skip to content

Commit 28b2307

Browse files
committed
check for undefined before setting xray trace
1 parent f0eba5f commit 28b2307

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/instrumentation-patch.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ function patchAwsSdkInstrumentation(instrumentation: Instrumentation): void {
311311
// Need to set capitalized version of the trace id to ensure that the Recursion Detection Middleware
312312
// of aws-sdk-js-v3 will detect the propagated X-Ray Context
313313
// See: https://github.com/aws/aws-sdk-js-v3/blob/v3.768.0/packages/middleware-recursion-detection/src/index.ts#L13
314-
middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER_CAPITALIZED] =
315-
middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER];
316-
delete middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER];
314+
const xray_trace_id = middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER];
315+
316+
if (xray_trace_id) {
317+
middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER_CAPITALIZED] = xray_trace_id;
318+
delete middlewareArgs.request.headers[AWSXRAY_TRACE_ID_HEADER];
319+
}
317320
const result = await next(middlewareArgs);
318321
return result;
319322
},

0 commit comments

Comments
 (0)