@@ -294,6 +294,7 @@ function patchAwsLambdaInstrumentation(instrumentation: Instrumentation): void {
294294// Override the upstream private _getV3SmithyClientSendPatch method to add middleware to inject X-Ray Trace Context into HTTP Headers
295295// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/instrumentation-aws-sdk-v0.48.0/plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts#L373-L384
296296const awsXrayPropagator = new AWSXRayPropagator ( ) ;
297+ const AWSXRAY_TRACE_ID_HEADER_CAPITALIZED = 'X-Amzn-Trace-Id' ;
297298const V3_CLIENT_CONFIG_KEY = Symbol ( 'opentelemetry.instrumentation.aws-sdk.client.config' ) ;
298299type V3PluginCommand = AwsV3Command < any , any , any , any , any > & {
299300 [ V3_CLIENT_CONFIG_KEY ] ?: any ;
@@ -307,6 +308,12 @@ function patchAwsSdkInstrumentation(instrumentation: Instrumentation): void {
307308 this . middlewareStack ?. add (
308309 ( next : any , context : any ) => async ( middlewareArgs : any ) => {
309310 awsXrayPropagator . inject ( otelContext . active ( ) , middlewareArgs . request . headers , defaultTextMapSetter ) ;
311+ // Need to set capitalized version of the trace id to ensure that the Recursion Detection Middleware
312+ // of aws-sdk-js-v3 will detect the propagated X-Ray Context
313+ // 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 ] ;
310317 const result = await next ( middlewareArgs ) ;
311318 return result ;
312319 } ,
0 commit comments