77import { Tracer } from '../../src' ;
88import { Callback , Context , Handler } from 'aws-lambda/handler' ;
99import { Segment , setContextMissingStrategy , Subsegment } from 'aws-xray-sdk-core' ;
10+ import { DynamoDB } from 'aws-sdk' ;
1011
1112interface LambdaInterface {
1213 handler : Handler
@@ -1057,29 +1058,27 @@ describe('Class: Tracer', () => {
10571058 const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
10581059
10591060 // Act
1060- tracer . captureAWSClient ( { } ) ;
1061+ const client = tracer . captureAWSClient ( new DynamoDB ( ) ) ;
10611062
10621063 // Assess
10631064 expect ( captureAWSClientSpy ) . toBeCalledTimes ( 0 ) ;
1065+ expect ( client ) . toBeInstanceOf ( DynamoDB ) ;
10641066
10651067 } ) ;
10661068
1067- test ( 'when called with a simple AWS SDK v2 client, it returns it back instrumented' , ( ) => {
1069+ test ( 'when called with a base AWS SDK v2 client, it returns it back instrumented' , ( ) => {
10681070
10691071 // Prepare
10701072 const tracer : Tracer = new Tracer ( ) ;
10711073 const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1072- // Minimum shape required for a regular AWS v2 client (i.e. AWS.S3) to be instrumented
1073- const dummyClient = {
1074- customizeRequests : ( ) => null ,
1075- } ;
10761074
10771075 // Act
1078- tracer . captureAWSClient ( dummyClient ) ;
1076+ const client = tracer . captureAWSClient ( new DynamoDB ( ) ) ;
10791077
10801078 // Assess
10811079 expect ( captureAWSClientSpy ) . toBeCalledTimes ( 1 ) ;
1082- expect ( captureAWSClientSpy ) . toBeCalledWith ( dummyClient ) ;
1080+ expect ( captureAWSClientSpy ) . toBeCalledWith ( client ) ;
1081+ expect ( client ) . toBeInstanceOf ( DynamoDB ) ;
10831082
10841083 } ) ;
10851084
@@ -1088,20 +1087,15 @@ describe('Class: Tracer', () => {
10881087 // Prepare
10891088 const tracer : Tracer = new Tracer ( ) ;
10901089 const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1091- // Minimum shape required for a complex AWS v2 client (i.e. AWS.DocumentClient) to be instrumented
1092- const dummyClient = {
1093- service : {
1094- customizeRequests : ( ) => null ,
1095- }
1096- } ;
10971090
10981091 // Act
1099- tracer . captureAWSClient ( dummyClient ) ;
1092+ const client = tracer . captureAWSClient ( new DynamoDB . DocumentClient ( ) ) ;
11001093
11011094 // Assess
11021095 expect ( captureAWSClientSpy ) . toBeCalledTimes ( 2 ) ;
1103- expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 1 , dummyClient ) ;
1104- expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 2 , dummyClient . service ) ;
1096+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 1 , client ) ;
1097+ expect ( captureAWSClientSpy ) . toHaveBeenNthCalledWith ( 2 , ( client as unknown as DynamoDB & { service : DynamoDB } ) . service ) ;
1098+ expect ( client ) . toBeInstanceOf ( DynamoDB . DocumentClient ) ;
11051099
11061100 } ) ;
11071101
0 commit comments