7
7
import { Tracer } from '../../src' ;
8
8
import { Callback , Context , Handler } from 'aws-lambda/handler' ;
9
9
import { Segment , setContextMissingStrategy , Subsegment } from 'aws-xray-sdk-core' ;
10
+ import { DynamoDB } from 'aws-sdk' ;
10
11
11
12
interface LambdaInterface {
12
13
handler : Handler
@@ -1057,29 +1058,27 @@ describe('Class: Tracer', () => {
1057
1058
const captureAWSClientSpy = jest . spyOn ( tracer . provider , 'captureAWSClient' ) ;
1058
1059
1059
1060
// Act
1060
- tracer . captureAWSClient ( { } ) ;
1061
+ const client = tracer . captureAWSClient ( new DynamoDB ( ) ) ;
1061
1062
1062
1063
// Assess
1063
1064
expect ( captureAWSClientSpy ) . toBeCalledTimes ( 0 ) ;
1065
+ expect ( client ) . toBeInstanceOf ( DynamoDB ) ;
1064
1066
1065
1067
} ) ;
1066
1068
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' , ( ) => {
1068
1070
1069
1071
// Prepare
1070
1072
const tracer : Tracer = new Tracer ( ) ;
1071
1073
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
- } ;
1076
1074
1077
1075
// Act
1078
- tracer . captureAWSClient ( dummyClient ) ;
1076
+ const client = tracer . captureAWSClient ( new DynamoDB ( ) ) ;
1079
1077
1080
1078
// Assess
1081
1079
expect ( captureAWSClientSpy ) . toBeCalledTimes ( 1 ) ;
1082
- expect ( captureAWSClientSpy ) . toBeCalledWith ( dummyClient ) ;
1080
+ expect ( captureAWSClientSpy ) . toBeCalledWith ( client ) ;
1081
+ expect ( client ) . toBeInstanceOf ( DynamoDB ) ;
1083
1082
1084
1083
} ) ;
1085
1084
@@ -1088,20 +1087,15 @@ describe('Class: Tracer', () => {
1088
1087
// Prepare
1089
1088
const tracer : Tracer = new Tracer ( ) ;
1090
1089
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
- } ;
1097
1090
1098
1091
// Act
1099
- tracer . captureAWSClient ( dummyClient ) ;
1092
+ const client = tracer . captureAWSClient ( new DynamoDB . DocumentClient ( ) ) ;
1100
1093
1101
1094
// Assess
1102
1095
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 ) ;
1105
1099
1106
1100
} ) ;
1107
1101
0 commit comments