@@ -38,9 +38,11 @@ const fakeCallback: Callback = (err, result) => {
38
38
return err ;
39
39
} ;
40
40
41
- function expectScopeSettings ( ) {
41
+ function expectScopeSettings ( fakeTransactionContext : any ) {
42
42
// @ts -ignore see "Why @ts-ignore" note
43
- expect ( Sentry . fakeScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
43
+ const fakeTransaction = { ...Sentry . fakeTransaction , ...fakeTransactionContext } ;
44
+ // @ts -ignore see "Why @ts-ignore" note
45
+ expect ( Sentry . fakeScope . setSpan ) . toBeCalledWith ( fakeTransaction ) ;
44
46
// @ts -ignore see "Why @ts-ignore" note
45
47
expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'server_name' , expect . anything ( ) ) ;
46
48
// @ts -ignore see "Why @ts-ignore" note
@@ -186,13 +188,17 @@ describe('AWSLambda', () => {
186
188
} ;
187
189
const wrappedHandler = wrapHandler ( handler ) ;
188
190
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
189
- expect ( rv ) . toStrictEqual ( 42 ) ;
190
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
191
+
192
+ const fakeTransactionContext = {
191
193
name : 'functionName' ,
192
194
op : 'awslambda.handler' ,
193
195
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
194
- } ) ;
195
- expectScopeSettings ( ) ;
196
+ } ;
197
+
198
+ expect ( rv ) . toStrictEqual ( 42 ) ;
199
+ // @ts -ignore see "Why @ts-ignore" note
200
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
201
+ expectScopeSettings ( fakeTransactionContext ) ;
196
202
// @ts -ignore see "Why @ts-ignore" note
197
203
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
198
204
expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
@@ -210,12 +216,15 @@ describe('AWSLambda', () => {
210
216
try {
211
217
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
212
218
} catch ( e ) {
213
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
219
+ const fakeTransactionContext = {
214
220
name : 'functionName' ,
215
221
op : 'awslambda.handler' ,
216
222
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
217
- } ) ;
218
- expectScopeSettings ( ) ;
223
+ } ;
224
+
225
+ // @ts -ignore see "Why @ts-ignore" note
226
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
227
+ expectScopeSettings ( fakeTransactionContext ) ;
219
228
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
220
229
// @ts -ignore see "Why @ts-ignore" note
221
230
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -244,7 +253,8 @@ describe('AWSLambda', () => {
244
253
} ;
245
254
246
255
const handler : Handler = ( _event , _context , callback ) => {
247
- expect ( Sentry . startTransaction ) . toBeCalledWith (
256
+ // @ts -ignore see "Why @ts-ignore" note
257
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith (
248
258
expect . objectContaining ( {
249
259
parentSpanId : '1121201211212012' ,
250
260
parentSampled : false ,
@@ -284,15 +294,18 @@ describe('AWSLambda', () => {
284
294
fakeEvent . headers = { 'sentry-trace' : '12312012123120121231201212312012-1121201211212012-0' } ;
285
295
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
286
296
} catch ( e ) {
287
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
297
+ const fakeTransactionContext = {
288
298
name : 'functionName' ,
289
299
op : 'awslambda.handler' ,
290
300
traceId : '12312012123120121231201212312012' ,
291
301
parentSpanId : '1121201211212012' ,
292
302
parentSampled : false ,
293
303
metadata : { baggage : [ { } , '' , false ] , source : 'component' } ,
294
- } ) ;
295
- expectScopeSettings ( ) ;
304
+ } ;
305
+
306
+ // @ts -ignore see "Why @ts-ignore" note
307
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
308
+ expectScopeSettings ( fakeTransactionContext ) ;
296
309
expect ( Sentry . captureException ) . toBeCalledWith ( e ) ;
297
310
// @ts -ignore see "Why @ts-ignore" note
298
311
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -310,13 +323,17 @@ describe('AWSLambda', () => {
310
323
} ;
311
324
const wrappedHandler = wrapHandler ( handler ) ;
312
325
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
313
- expect ( rv ) . toStrictEqual ( 42 ) ;
314
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
326
+
327
+ const fakeTransactionContext = {
315
328
name : 'functionName' ,
316
329
op : 'awslambda.handler' ,
317
330
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
318
- } ) ;
319
- expectScopeSettings ( ) ;
331
+ } ;
332
+
333
+ expect ( rv ) . toStrictEqual ( 42 ) ;
334
+ // @ts -ignore see "Why @ts-ignore" note
335
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
336
+ expectScopeSettings ( fakeTransactionContext ) ;
320
337
// @ts -ignore see "Why @ts-ignore" note
321
338
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
322
339
expect ( Sentry . flush ) . toBeCalled ( ) ;
@@ -345,12 +362,15 @@ describe('AWSLambda', () => {
345
362
try {
346
363
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
347
364
} catch ( e ) {
348
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
365
+ const fakeTransactionContext = {
349
366
name : 'functionName' ,
350
367
op : 'awslambda.handler' ,
351
368
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
352
- } ) ;
353
- expectScopeSettings ( ) ;
369
+ } ;
370
+
371
+ // @ts -ignore see "Why @ts-ignore" note
372
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
373
+ expectScopeSettings ( fakeTransactionContext ) ;
354
374
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
355
375
// @ts -ignore see "Why @ts-ignore" note
356
376
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -383,13 +403,17 @@ describe('AWSLambda', () => {
383
403
} ;
384
404
const wrappedHandler = wrapHandler ( handler ) ;
385
405
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
386
- expect ( rv ) . toStrictEqual ( 42 ) ;
387
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
406
+
407
+ const fakeTransactionContext = {
388
408
name : 'functionName' ,
389
409
op : 'awslambda.handler' ,
390
410
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
391
- } ) ;
392
- expectScopeSettings ( ) ;
411
+ } ;
412
+
413
+ expect ( rv ) . toStrictEqual ( 42 ) ;
414
+ // @ts -ignore see "Why @ts-ignore" note
415
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
416
+ expectScopeSettings ( fakeTransactionContext ) ;
393
417
// @ts -ignore see "Why @ts-ignore" note
394
418
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
395
419
expect ( Sentry . flush ) . toBeCalled ( ) ;
@@ -418,12 +442,15 @@ describe('AWSLambda', () => {
418
442
try {
419
443
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
420
444
} catch ( e ) {
421
- expect ( Sentry . startTransaction ) . toBeCalledWith ( {
445
+ const fakeTransactionContext = {
422
446
name : 'functionName' ,
423
447
op : 'awslambda.handler' ,
424
448
metadata : { baggage : [ { } , '' , true ] , source : 'component' } ,
425
- } ) ;
426
- expectScopeSettings ( ) ;
449
+ } ;
450
+
451
+ // @ts -ignore see "Why @ts-ignore" note
452
+ expect ( Sentry . fakeHub . startTransaction ) . toBeCalledWith ( fakeTransactionContext ) ;
453
+ expectScopeSettings ( fakeTransactionContext ) ;
427
454
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
428
455
// @ts -ignore see "Why @ts-ignore" note
429
456
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
0 commit comments