@@ -37,6 +37,7 @@ import * as nock from 'nock';
3737import { ReadableSpan , Span as SDKSpan } from '@opentelemetry/sdk-trace-base' ;
3838import { getTestSpans } from '@opentelemetry/contrib-test-utils' ;
3939import { instrumentationConfigs } from '../../src/register' ;
40+ import { STS } from '@aws-sdk/client-sts' ;
4041
4142// It is assumed that bedrock.test.ts has already registered the
4243// necessary instrumentations for testing by calling:
@@ -692,6 +693,41 @@ describe('InstrumentationPatchTest', () => {
692693 } ) ;
693694 } ) ;
694695
696+ it ( 'prevents recursion when credentials provider makes STS calls' , async ( ) => {
697+ let credentialsCallCount = 0 ;
698+
699+ // Create separate STS client for credential fetching
700+ const credentialsStsClient = new STS ( { region : 'us-east-1' } ) ;
701+
702+ // Create main client with credentials provider that calls STS
703+ const mainClient = new Lambda ( {
704+ region : 'us-east-1' ,
705+ credentials : async ( ) => {
706+ credentialsCallCount ++ ;
707+ // Simulate STS call for credentials (this should be skipped on recursion)
708+ await credentialsStsClient . getCallerIdentity ( { } ) . catch ( ( err : any ) => { } ) ;
709+ return { accessKeyId : 'sts-access-key' , secretAccessKey : 'secret' } ;
710+ } ,
711+ } ) ;
712+
713+ // Mock HTTP responses
714+ nock ( 'https://sts.us-east-1.amazonaws.com' )
715+ . post ( '/' )
716+ . reply ( 200 , '<GetCallerIdentityResponse></GetCallerIdentityResponse>' ) ;
717+
718+ nock ( 'https://lambda.us-east-1.amazonaws.com' ) . post ( '/2015-03-31/functions/test/invocations' ) . reply ( 200 , 'null' ) ;
719+
720+ // Make Lambda call - this triggers credential extraction which calls STS
721+ await mainClient . invoke ( { FunctionName : 'test' } ) . catch ( ( err : any ) => { } ) ;
722+
723+ const testSpans = getTestSpans ( ) ;
724+ const lambdaSpans = testSpans . filter ( s => s . name . includes ( 'test Invoke' ) ) ;
725+
726+ expect ( lambdaSpans . length ) . toBe ( 1 ) ;
727+ expect ( credentialsCallCount ) . toBe ( 1 ) ;
728+ expect ( lambdaSpans [ 0 ] . attributes [ AWS_ATTRIBUTE_KEYS . AWS_AUTH_ACCOUNT_ACCESS_KEY ] ) . toBe ( 'sts-access-key' ) ;
729+ } ) ;
730+
695731 it ( 'injects trace context header into request via propagator' , async ( ) => {
696732 lambda = new Lambda ( {
697733 region : region ,
0 commit comments