@@ -417,20 +417,20 @@ function patchAwsSdkCredentialExtraction(instrumentation: Instrumentation): void
417
417
const originalHandler = originalPatch . call ( this , moduleVersion , original ) ;
418
418
419
419
return function ( this : any , _handler : any , awsExecutionContext : HandlerExecutionContext ) {
420
- const resolvedHandler = originalHandler . call ( this , _handler , awsExecutionContext ) ;
420
+ const origPatchedHandler = originalHandler . call ( this , _handler , awsExecutionContext ) ;
421
421
422
- return function ( this : any , command : any ) : Promise < any > {
423
- // Suppress tracing **before** resolving credentials to avoid recursive send() triggering our instrumentation again
424
- return otelContext . with ( suppressTracing ( otelContext . active ( ) ) , async ( ) => {
422
+ return async function ( this : any , command : any ) : Promise < any > {
423
+ const clientConfig = command [ V3_CLIENT_CONFIG_KEY ] ;
424
+ const originalPromise = origPatchedHandler . call ( this , command ) ;
425
+
426
+ await otelContext . with ( suppressTracing ( otelContext . active ( ) ) , async ( ) => {
425
427
try {
426
- const clientConfig = command [ V3_CLIENT_CONFIG_KEY ] ;
427
428
const [ credentials , region ] = await Promise . all ( [
428
429
clientConfig ?. credentials ?.( ) ,
429
430
clientConfig ?. region ?.( ) ,
430
431
] ) ;
431
432
432
- const activeContext = otelContext . active ( ) ;
433
- const span = trace . getSpan ( activeContext ) ;
433
+ const span = trace . getActiveSpan ( ) ;
434
434
if ( span ) {
435
435
if ( credentials ?. accessKeyId ) {
436
436
span . setAttribute ( AWS_ATTRIBUTE_KEYS . AWS_AUTH_ACCOUNT_ACCESS_KEY , credentials . accessKeyId ) ;
@@ -442,10 +442,8 @@ function patchAwsSdkCredentialExtraction(instrumentation: Instrumentation): void
442
442
} catch ( e ) {
443
443
// Don't crash or log unless debugging
444
444
}
445
-
446
- // Now proceed with the handler (unsuppressed, so actual span can record API call)
447
- return resolvedHandler . call ( this , command ) ;
448
445
} ) ;
446
+ return originalPromise ;
449
447
} ;
450
448
} ;
451
449
} ;
0 commit comments