@@ -47,6 +47,11 @@ const responseMockSuccess = {
47
47
const topicName = 'topic' ;
48
48
const fakeARN = `arn:aws:sns:region:000000000:${ topicName } ` ;
49
49
50
+ const hookSpy = sinon . spy (
51
+ ( instrumentation [ 'servicesExtensions' ] as any ) [ 'services' ] . get ( 'SNS' ) ,
52
+ 'requestPostSpanHook'
53
+ ) ;
54
+
50
55
describe ( 'SNS - v2' , ( ) => {
51
56
before ( ( ) => {
52
57
AWSv2 . config . credentials = {
@@ -64,6 +69,10 @@ describe('SNS - v2', () => {
64
69
} as AWS . SNS . Types . PublishResponse ) ;
65
70
} ) ;
66
71
72
+ afterEach ( ( ) => {
73
+ hookSpy . resetHistory ( ) ;
74
+ } )
75
+
67
76
describe ( 'publish' , ( ) => {
68
77
it ( 'topic arn' , async ( ) => {
69
78
const sns = new AWSv2 . SNS ( ) ;
@@ -120,10 +129,6 @@ describe('SNS - v2', () => {
120
129
121
130
it ( 'inject context propagation' , async ( ) => {
122
131
const sns = new AWSv2 . SNS ( ) ;
123
- const hookSpy = sinon . spy (
124
- ( instrumentation [ 'servicesExtensions' ] as any ) [ 'services' ] . get ( 'SNS' ) ,
125
- 'requestPostSpanHook'
126
- ) ;
127
132
128
133
await sns
129
134
. publish ( {
@@ -180,16 +185,18 @@ describe('SNS - v3', () => {
180
185
secretAccessKey : 'abcde' ,
181
186
} ,
182
187
} ) ;
188
+ } ) ;
183
189
184
- nock ( 'https://sns.us-east-1.amazonaws.com/' )
190
+ describe ( 'publish' , ( ) => {
191
+ beforeEach ( ( ) => {
192
+ nock ( 'https://sns.us-east-1.amazonaws.com/' )
185
193
. post ( '/' )
186
194
. reply (
187
195
200 ,
188
196
fs . readFileSync ( './test/mock-responses/sns-publish.xml' , 'utf8' )
189
197
) ;
190
- } ) ;
198
+ } ) ;
191
199
192
- describe ( 'publish' , ( ) => {
193
200
it ( 'topic arn' , async ( ) => {
194
201
const topicV3Name = 'dummy-sns-v3-topic' ;
195
202
const topicV3ARN = `arn:aws:sns:us-east-1:000000000:${ topicV3Name } ` ;
@@ -236,4 +243,29 @@ describe('SNS - v3', () => {
236
243
) ;
237
244
} ) ;
238
245
} ) ;
246
+
247
+ describe ( 'publish batch' , ( ) => {
248
+ it ( 'inject context propagation for publish batch command' , async ( ) => {
249
+ nock ( 'https://sns.us-east-1.amazonaws.com/' )
250
+ . post ( '/' )
251
+ . reply (
252
+ 200 ,
253
+ fs . readFileSync ( './test/mock-responses/sns-publish-batch.xml' , 'utf8' )
254
+ ) ;
255
+
256
+ await sns
257
+ . publishBatch ( {
258
+ TopicArn : fakeARN ,
259
+ PublishBatchRequestEntries : [ { Id : '1' , Message : 'sns message' } ]
260
+ } ) ;
261
+
262
+ const publishSpans = getTestSpans ( ) . filter (
263
+ ( s : ReadableSpan ) => s . name === `${ topicName } send`
264
+ ) ;
265
+ expect ( publishSpans . length ) . toBe ( 1 ) ;
266
+ expect (
267
+ hookSpy . args [ 0 ] [ 0 ] . commandInput . PublishBatchRequestEntries [ 0 ] . MessageAttributes . traceparent
268
+ ) . toBeDefined ( ) ;
269
+ } ) ;
270
+ } ) ;
239
271
} ) ;
0 commit comments