@@ -41,6 +41,36 @@ const fakeCallback: Callback = (err, result) => {
41
41
return err ;
42
42
} ;
43
43
44
+ function expectScopeSettings ( ) {
45
+ // @ts -ignore see "Why @ts-ignore" note
46
+ expect ( Sentry . fakeScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
47
+ // @ts -ignore see "Why @ts-ignore" note
48
+ expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'server_name' , expect . anything ( ) ) ;
49
+ // @ts -ignore see "Why @ts-ignore" note
50
+ expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'url' , 'awslambda:///functionName' ) ;
51
+ // @ts -ignore see "Why @ts-ignore" note
52
+ expect ( Sentry . fakeScope . setContext ) . toBeCalledWith ( 'runtime' , { name : 'node' , version : expect . anything ( ) } ) ;
53
+ // @ts -ignore see "Why @ts-ignore" note
54
+ expect ( Sentry . fakeScope . setContext ) . toBeCalledWith (
55
+ 'aws.lambda' ,
56
+ expect . objectContaining ( {
57
+ aws_request_id : 'awsRequestId' ,
58
+ function_name : 'functionName' ,
59
+ function_version : 'functionVersion' ,
60
+ invoked_function_arn : 'invokedFunctionArn' ,
61
+ remaining_time_in_millis : 100 ,
62
+ } ) ,
63
+ ) ;
64
+ // @ts -ignore see "Why @ts-ignore" note
65
+ expect ( Sentry . fakeScope . setContext ) . toBeCalledWith (
66
+ 'aws.cloudwatch.logs' ,
67
+ expect . objectContaining ( {
68
+ log_group : 'logGroupName' ,
69
+ log_stream : 'logStreamName' ,
70
+ } ) ,
71
+ ) ;
72
+ }
73
+
44
74
describe ( 'AWSLambda' , ( ) => {
45
75
afterEach ( ( ) => {
46
76
// @ts -ignore see "Why @ts-ignore" note
@@ -140,7 +170,7 @@ describe('AWSLambda', () => {
140
170
141
171
describe ( 'wrapHandler() on sync handler' , ( ) => {
142
172
test ( 'successful execution' , async ( ) => {
143
- expect . assertions ( 5 ) ;
173
+ expect . assertions ( 10 ) ;
144
174
145
175
const handler : Handler = ( _event , _context , callback ) => {
146
176
callback ( null , 42 ) ;
@@ -149,15 +179,14 @@ describe('AWSLambda', () => {
149
179
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
150
180
expect ( rv ) . toStrictEqual ( 42 ) ;
151
181
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
152
- // @ts -ignore see "Why @ts-ignore" note
153
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
182
+ expectScopeSettings ( ) ;
154
183
// @ts -ignore see "Why @ts-ignore" note
155
184
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
156
185
expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
157
186
} ) ;
158
187
159
188
test ( 'unsuccessful execution' , async ( ) => {
160
- expect . assertions ( 5 ) ;
189
+ expect . assertions ( 10 ) ;
161
190
162
191
const error = new Error ( 'sorry' ) ;
163
192
const handler : Handler = ( _event , _context , callback ) => {
@@ -169,8 +198,7 @@ describe('AWSLambda', () => {
169
198
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
170
199
} catch ( e ) {
171
200
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
172
- // @ts -ignore see "Why @ts-ignore" note
173
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
201
+ expectScopeSettings ( ) ;
174
202
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
175
203
// @ts -ignore see "Why @ts-ignore" note
176
204
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -191,7 +219,7 @@ describe('AWSLambda', () => {
191
219
} ) ;
192
220
193
221
test ( 'capture error' , async ( ) => {
194
- expect . assertions ( 5 ) ;
222
+ expect . assertions ( 10 ) ;
195
223
196
224
const error = new Error ( 'wat' ) ;
197
225
const handler : Handler = ( _event , _context , _callback ) => {
@@ -203,8 +231,7 @@ describe('AWSLambda', () => {
203
231
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
204
232
} catch ( e ) {
205
233
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
206
- // @ts -ignore see "Why @ts-ignore" note
207
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
234
+ expectScopeSettings ( ) ;
208
235
expect ( Sentry . captureException ) . toBeCalledWith ( e ) ;
209
236
// @ts -ignore see "Why @ts-ignore" note
210
237
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -215,7 +242,7 @@ describe('AWSLambda', () => {
215
242
216
243
describe ( 'wrapHandler() on async handler' , ( ) => {
217
244
test ( 'successful execution' , async ( ) => {
218
- expect . assertions ( 5 ) ;
245
+ expect . assertions ( 10 ) ;
219
246
220
247
const handler : Handler = async ( _event , _context ) => {
221
248
return 42 ;
@@ -224,8 +251,7 @@ describe('AWSLambda', () => {
224
251
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
225
252
expect ( rv ) . toStrictEqual ( 42 ) ;
226
253
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
227
- // @ts -ignore see "Why @ts-ignore" note
228
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
254
+ expectScopeSettings ( ) ;
229
255
// @ts -ignore see "Why @ts-ignore" note
230
256
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
231
257
expect ( Sentry . flush ) . toBeCalled ( ) ;
@@ -243,7 +269,7 @@ describe('AWSLambda', () => {
243
269
} ) ;
244
270
245
271
test ( 'capture error' , async ( ) => {
246
- expect . assertions ( 5 ) ;
272
+ expect . assertions ( 10 ) ;
247
273
248
274
const error = new Error ( 'wat' ) ;
249
275
const handler : Handler = async ( _event , _context ) => {
@@ -255,8 +281,7 @@ describe('AWSLambda', () => {
255
281
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
256
282
} catch ( e ) {
257
283
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
258
- // @ts -ignore see "Why @ts-ignore" note
259
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
284
+ expectScopeSettings ( ) ;
260
285
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
261
286
// @ts -ignore see "Why @ts-ignore" note
262
287
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
@@ -267,7 +292,7 @@ describe('AWSLambda', () => {
267
292
268
293
describe ( 'wrapHandler() on async handler with a callback method (aka incorrect usage)' , ( ) => {
269
294
test ( 'successful execution' , async ( ) => {
270
- expect . assertions ( 5 ) ;
295
+ expect . assertions ( 10 ) ;
271
296
272
297
const handler : Handler = async ( _event , _context , _callback ) => {
273
298
return 42 ;
@@ -276,8 +301,7 @@ describe('AWSLambda', () => {
276
301
const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
277
302
expect ( rv ) . toStrictEqual ( 42 ) ;
278
303
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
279
- // @ts -ignore see "Why @ts-ignore" note
280
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
304
+ expectScopeSettings ( ) ;
281
305
// @ts -ignore see "Why @ts-ignore" note
282
306
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
283
307
expect ( Sentry . flush ) . toBeCalled ( ) ;
@@ -295,7 +319,7 @@ describe('AWSLambda', () => {
295
319
} ) ;
296
320
297
321
test ( 'capture error' , async ( ) => {
298
- expect . assertions ( 5 ) ;
322
+ expect . assertions ( 10 ) ;
299
323
300
324
const error = new Error ( 'wat' ) ;
301
325
const handler : Handler = async ( _event , _context , _callback ) => {
@@ -307,8 +331,7 @@ describe('AWSLambda', () => {
307
331
await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
308
332
} catch ( e ) {
309
333
expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
310
- // @ts -ignore see "Why @ts-ignore" note
311
- expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
334
+ expectScopeSettings ( ) ;
312
335
expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
313
336
// @ts -ignore see "Why @ts-ignore" note
314
337
expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
0 commit comments