File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import {
18
18
setLogger ,
19
19
Logger ,
20
20
} from 'aws-xray-sdk-core' ;
21
+ import { addUserAgentMiddleware } from '@aws-lambda-powertools/commons' ;
21
22
22
23
class ProviderService implements ProviderServiceInterface {
23
24
public captureAWS < T > ( awssdk : T ) : T {
@@ -29,6 +30,8 @@ class ProviderService implements ProviderServiceInterface {
29
30
}
30
31
31
32
public captureAWSv3Client < T > ( service : T ) : T {
33
+ addUserAgentMiddleware ( service , 'tracer' ) ;
34
+
32
35
// Type must be aliased as any because of this https://github.com/aws/aws-xray-sdk-node/issues/439#issuecomment-859715660
33
36
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34
37
return captureAWSv3Client ( service as any ) ;
Original file line number Diff line number Diff line change 6
6
7
7
import { ProviderService } from '../../src/provider' ;
8
8
import {
9
+ captureAsyncFunc ,
9
10
captureAWS ,
10
11
captureAWSClient ,
11
12
captureAWSv3Client ,
12
- captureAsyncFunc ,
13
- captureHTTPsGlobal ,
14
13
captureFunc ,
14
+ captureHTTPsGlobal ,
15
15
getNamespace ,
16
16
getSegment ,
17
+ Segment ,
17
18
setContextMissingStrategy ,
18
19
setDaemonAddress ,
19
20
setLogger ,
20
21
setSegment ,
21
22
Subsegment ,
22
- Segment ,
23
23
} from 'aws-xray-sdk-core' ;
24
24
import http from 'http' ;
25
25
import https from 'https' ;
26
+ import { DynamoDBClient } from '@aws-sdk/client-dynamodb' ;
27
+ import * as UserAgentMiddleware from '@aws-lambda-powertools/commons/lib/userAgentMiddleware' ;
26
28
27
29
jest . mock ( 'aws-xray-sdk-core' , ( ) => ( {
28
30
...jest . requireActual ( 'aws-xray-sdk-core' ) ,
@@ -85,6 +87,22 @@ describe('Class: ProviderService', () => {
85
87
expect ( captureAWSv3Client ) . toHaveBeenCalledTimes ( 1 ) ;
86
88
expect ( captureAWSv3Client ) . toHaveBeenCalledWith ( { } ) ;
87
89
} ) ;
90
+
91
+ test ( 'when called, it adds the correct user agent middleware' , ( ) => {
92
+ // Prepare
93
+ const provider : ProviderService = new ProviderService ( ) ;
94
+
95
+ // spy on addUserAgentMiddleware
96
+ const spy = jest . spyOn ( UserAgentMiddleware , 'addUserAgentMiddleware' ) ;
97
+
98
+ // Act
99
+ const dynamoDBClient = new DynamoDBClient ( { } ) ;
100
+ provider . captureAWSv3Client ( dynamoDBClient ) ;
101
+
102
+ // Assess
103
+ expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
104
+ expect ( spy ) . toHaveBeenCalledWith ( dynamoDBClient , 'tracer' ) ;
105
+ } ) ;
88
106
} ) ;
89
107
90
108
describe ( 'Method: captureAsyncFunc' , ( ) => {
You can’t perform that action at this time.
0 commit comments