@@ -58,6 +58,8 @@ const _BEDROCK_GUARDRAIL_ARN: string = 'arn:aws:bedrock:us-east-1:123456789012:g
5858const _BEDROCK_KNOWLEDGEBASE_ID : string = 'KnowledgeBaseId' ;
5959const _GEN_AI_SYSTEM : string = 'aws.bedrock' ;
6060const _GEN_AI_REQUEST_MODEL : string = 'genAiReuqestModelId' ;
61+ const _STREAM_ARN : string = 'arn:aws:kinesis:us-west-2:123456789012:stream/testStream' ;
62+ const _TABLE_ARN : string = 'arn:aws:dynamodb:us-west-2:123456789012:table/testTable' ;
6163
6264const mockHeaders = {
6365 'x-test-header' : 'test-value' ,
@@ -90,6 +92,8 @@ describe('InstrumentationPatchTest', () => {
9092 expect ( services . get ( 'Lambda' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
9193 expect ( services . get ( 'SQS' ) . _requestPreSpanHook ) . toBeFalsy ( ) ;
9294 expect ( services . get ( 'SQS' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
95+ expect ( services . get ( 'Kinesis' ) . _requestPreSpanHook ) . toBeFalsy ( ) ;
96+ expect ( services . get ( 'Kinesis' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
9397 expect ( services . has ( 'Bedrock' ) ) . toBeFalsy ( ) ;
9498 expect ( services . has ( 'BedrockAgent' ) ) . toBeFalsy ( ) ;
9599 expect ( services . get ( 'BedrockAgentRuntime' ) ) . toBeFalsy ( ) ;
@@ -119,6 +123,8 @@ describe('InstrumentationPatchTest', () => {
119123 expect ( services . get ( 'Lambda' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
120124 expect ( services . get ( 'SQS' ) . _requestPreSpanHook ) . toBeTruthy ( ) ;
121125 expect ( services . get ( 'SQS' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
126+ expect ( services . get ( 'Kinesis' ) . _requestPreSpanHook ) . toBeTruthy ( ) ;
127+ expect ( services . get ( 'Kinesis' ) . requestPreSpanHook ) . toBeTruthy ( ) ;
122128 expect ( services . has ( 'Bedrock' ) ) . toBeTruthy ( ) ;
123129 expect ( services . has ( 'BedrockAgent' ) ) . toBeTruthy ( ) ;
124130 expect ( services . get ( 'BedrockAgentRuntime' ) ) . toBeTruthy ( ) ;
@@ -179,6 +185,14 @@ describe('InstrumentationPatchTest', () => {
179185 expect ( ( ) => doExtractBedrockAttributes ( services , 'Bedrock' ) ) . toThrow ( ) ;
180186 } ) ;
181187
188+ it ( 'Kinesis without patching' , ( ) => {
189+ const unpatchedAwsSdkInstrumentation : AwsInstrumentation = extractAwsSdkInstrumentation ( UNPATCHED_INSTRUMENTATIONS ) ;
190+ const services : Map < string , any > = extractServicesFromAwsSdkInstrumentation ( unpatchedAwsSdkInstrumentation ) ;
191+ expect ( ( ) => doExtractKinesisAttributes ( services ) ) . not . toThrow ( ) ;
192+ const kinesisAttributes : Attributes = doExtractKinesisAttributes ( services ) ;
193+ expect ( kinesisAttributes [ AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_ARN ] ) . toBeUndefined ( ) ;
194+ } ) ;
195+
182196 it ( 'SNS with patching' , ( ) => {
183197 const patchedAwsSdkInstrumentation : AwsInstrumentation = extractAwsSdkInstrumentation ( PATCHED_INSTRUMENTATIONS ) ;
184198 const services : Map < string , any > = extractServicesFromAwsSdkInstrumentation ( patchedAwsSdkInstrumentation ) ;
@@ -233,6 +247,20 @@ describe('InstrumentationPatchTest', () => {
233247 expect ( responseHookSecretsManagerAttributes [ AWS_ATTRIBUTE_KEYS . AWS_SECRETSMANAGER_SECRET_ARN ] ) . toBe ( _SECRETS_ARN ) ;
234248 } ) ;
235249
250+ it ( 'Kinesis with patching' , ( ) => {
251+ const patchedAwsSdkInstrumentation : AwsInstrumentation = extractAwsSdkInstrumentation ( PATCHED_INSTRUMENTATIONS ) ;
252+ const services : Map < string , any > = extractServicesFromAwsSdkInstrumentation ( patchedAwsSdkInstrumentation ) ;
253+ const requestKinesisAttributes : Attributes = doExtractKinesisAttributes ( services ) ;
254+ expect ( requestKinesisAttributes [ AWS_ATTRIBUTE_KEYS . AWS_KINESIS_STREAM_ARN ] ) . toEqual ( _STREAM_ARN ) ;
255+ } ) ;
256+
257+ it ( 'DynamoDB with patching' , ( ) => {
258+ const patchedAwsSdkInstrumentation : AwsInstrumentation = extractAwsSdkInstrumentation ( PATCHED_INSTRUMENTATIONS ) ;
259+ const services : Map < string , any > = extractServicesFromAwsSdkInstrumentation ( patchedAwsSdkInstrumentation ) ;
260+ const responseDynamoDbAttributes : Attributes = doResponseHookDynamoDb ( services ) ;
261+ expect ( responseDynamoDbAttributes [ AWS_ATTRIBUTE_KEYS . AWS_DYNAMODB_TABLE_ARN ] ) . toEqual ( _TABLE_ARN ) ;
262+ } ) ;
263+
236264 it ( 'Bedrock with patching' , ( ) => {
237265 const patchedAwsSdkInstrumentation : AwsInstrumentation = extractAwsSdkInstrumentation ( PATCHED_INSTRUMENTATIONS ) ;
238266 const services : Map < string , any > = extractServicesFromAwsSdkInstrumentation ( patchedAwsSdkInstrumentation ) ;
@@ -446,6 +474,18 @@ describe('InstrumentationPatchTest', () => {
446474 return doExtractAttributes ( services , serviceName , params ) ;
447475 }
448476
477+ function doExtractKinesisAttributes ( services : Map < string , ServiceExtension > ) : Attributes {
478+ const serviceName : string = 'Kinesis' ;
479+ const params : NormalizedRequest = {
480+ serviceName : serviceName ,
481+ commandName : 'mockCommandName' ,
482+ commandInput : {
483+ StreamARN : _STREAM_ARN ,
484+ } ,
485+ } ;
486+ return doExtractAttributes ( services , serviceName , params ) ;
487+ }
488+
449489 function doExtractAttributes (
450490 services : Map < string , ServiceExtension > ,
451491 serviceName : string ,
@@ -492,6 +532,23 @@ describe('InstrumentationPatchTest', () => {
492532 return doResponseHook ( services , 'Lambda' , results as NormalizedResponse ) ;
493533 }
494534
535+ function doResponseHookDynamoDb ( services : Map < string , ServiceExtension > ) : Attributes {
536+ const results : Partial < NormalizedResponse > = {
537+ data : {
538+ Table : {
539+ TableArn : _TABLE_ARN ,
540+ } ,
541+ } ,
542+ request : {
543+ commandInput : { } ,
544+ commandName : 'dummy_operation' ,
545+ serviceName : 'DynamoDB' ,
546+ } ,
547+ } ;
548+
549+ return doResponseHook ( services , 'DynamoDB' , results as NormalizedResponse ) ;
550+ }
551+
495552 function doResponseHookBedrock (
496553 services : Map < string , ServiceExtension > ,
497554 serviceName : string ,
@@ -563,9 +620,13 @@ describe('InstrumentationPatchTest', () => {
563620 mockedMiddlewareStack = {
564621 add : ( arg1 : any , arg2 : any ) => mockedMiddlewareStackInternal . push ( [ arg1 , arg2 ] ) ,
565622 } ;
623+ const mockConfig = {
624+ credentials : ( ) => Promise . resolve ( { accessKeyId : 'test-access-key' } ) ,
625+ region : ( ) => Promise . resolve ( 'us-west-2' ) ,
626+ } ;
566627 const send = extractAwsSdkInstrumentation ( PATCHED_INSTRUMENTATIONS )
567628 [ '_getV3SmithyClientSendPatch' ] ( ( ...args : unknown [ ] ) => Promise . resolve ( ) )
568- . bind ( { middlewareStack : mockedMiddlewareStack } ) ;
629+ . bind ( { middlewareStack : mockedMiddlewareStack , config : mockConfig } ) ;
569630
570631 middlewareArgsHeader = {
571632 request : {
@@ -617,6 +678,18 @@ describe('InstrumentationPatchTest', () => {
617678
618679 expect ( mockedMiddlewareStackInternal [ 0 ] [ 1 ] . name ) . toEqual ( '_adotInjectXrayContextMiddleware' ) ;
619680 } ) ;
681+
682+ it ( 'Add cross account information span attributes from STS credentials' , async ( ) => {
683+ const mockSpan = { setAttribute : sinon . stub ( ) } ;
684+ sinon . stub ( trace , 'getSpan' ) . returns ( mockSpan as unknown as Span ) ;
685+ const credentialsMiddlewareArgs : any = { } ;
686+ await mockedMiddlewareStackInternal [ 1 ] [ 0 ] ( ( arg : any ) => Promise . resolve ( arg ) , null ) ( credentialsMiddlewareArgs ) ;
687+ expect ( mockedMiddlewareStackInternal [ 1 ] [ 1 ] . name ) . toEqual ( '_extractSignerCredentials' ) ;
688+ expect (
689+ mockSpan . setAttribute . calledWith ( AWS_ATTRIBUTE_KEYS . AWS_AUTH_ACCESS_KEY , 'test-access-key' )
690+ ) . toBeTruthy ( ) ;
691+ expect ( mockSpan . setAttribute . calledWith ( AWS_ATTRIBUTE_KEYS . AWS_AUTH_REGION , 'us-west-2' ) ) . toBeTruthy ( ) ;
692+ } ) ;
620693 } ) ;
621694
622695 it ( 'injects trace context header into request via propagator' , async ( ) => {
0 commit comments