@@ -51,17 +51,11 @@ describe('AWSLambda', () => {
5151 test ( 'flushTimeout' , async ( ) => {
5252 expect . assertions ( 1 ) ;
5353
54- const error = new Error ( 'wat' ) ;
55- const handler = ( ) => {
56- throw error ;
57- } ;
54+ const handler = ( ) => { } ;
5855 const wrappedHandler = wrapHandler ( handler , { flushTimeout : 1337 } ) ;
5956
60- try {
61- await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
62- } catch ( e ) {
63- expect ( Sentry . flush ) . toBeCalledWith ( 1337 ) ;
64- }
57+ await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
58+ expect ( Sentry . flush ) . toBeCalledWith ( 1337 ) ;
6559 } ) ;
6660
6761 test ( 'rethrowAfterCapture' , async ( ) => {
@@ -142,22 +136,50 @@ describe('AWSLambda', () => {
142136 // @ts -ignore see "Why @ts-ignore" note
143137 expect ( Sentry . fakeScope . setTag ) . toBeCalledWith ( 'timeout' , '1m40s' ) ;
144138 } ) ;
139+
140+ test ( 'tracing enabled' , async ( ) => {
141+ expect . assertions ( 1 ) ;
142+
143+ const handler : Handler = ( _event , _context , callback ) => {
144+ callback ( null , 42 ) ;
145+ } ;
146+ const wrappedHandler = wrapHandler ( handler , { tracing : true } ) ;
147+ await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
148+ expect ( Sentry . startTransaction ) . toBeCalled ( ) ;
149+ } ) ;
150+
151+ test ( 'tracing disabled' , async ( ) => {
152+ expect . assertions ( 1 ) ;
153+
154+ const handler : Handler = ( _event , _context , callback ) => {
155+ callback ( null , 42 ) ;
156+ } ;
157+ const wrappedHandler = wrapHandler ( handler , { tracing : false } ) ;
158+ await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
159+ expect ( Sentry . startTransaction ) . not . toBeCalled ( ) ;
160+ } ) ;
145161 } ) ;
146162
147163 describe ( 'wrapHandler() on sync handler' , ( ) => {
148164 test ( 'successful execution' , async ( ) => {
149- expect . assertions ( 1 ) ;
165+ expect . assertions ( 5 ) ;
150166
151167 const handler : Handler = ( _event , _context , callback ) => {
152168 callback ( null , 42 ) ;
153169 } ;
154170 const wrappedHandler = wrapHandler ( handler ) ;
155171 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
156172 expect ( rv ) . toStrictEqual ( 42 ) ;
173+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
174+ // @ts -ignore see "Why @ts-ignore" note
175+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
176+ // @ts -ignore see "Why @ts-ignore" note
177+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
178+ expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
157179 } ) ;
158180
159181 test ( 'unsuccessful execution' , async ( ) => {
160- expect . assertions ( 2 ) ;
182+ expect . assertions ( 5 ) ;
161183
162184 const error = new Error ( 'sorry' ) ;
163185 const handler : Handler = ( _event , _context , callback ) => {
@@ -168,7 +190,12 @@ describe('AWSLambda', () => {
168190 try {
169191 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
170192 } catch ( e ) {
193+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
194+ // @ts -ignore see "Why @ts-ignore" note
195+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
171196 expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
197+ // @ts -ignore see "Why @ts-ignore" note
198+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
172199 expect ( Sentry . flush ) . toBeCalledWith ( 2000 ) ;
173200 }
174201 } ) ;
@@ -186,7 +213,7 @@ describe('AWSLambda', () => {
186213 } ) ;
187214
188215 test ( 'capture error' , async ( ) => {
189- expect . assertions ( 2 ) ;
216+ expect . assertions ( 5 ) ;
190217
191218 const error = new Error ( 'wat' ) ;
192219 const handler : Handler = ( _event , _context , _callback ) => {
@@ -197,22 +224,33 @@ describe('AWSLambda', () => {
197224 try {
198225 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
199226 } catch ( e ) {
200- expect ( Sentry . captureException ) . toBeCalled ( ) ;
227+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
228+ // @ts -ignore see "Why @ts-ignore" note
229+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
230+ expect ( Sentry . captureException ) . toBeCalledWith ( e ) ;
231+ // @ts -ignore see "Why @ts-ignore" note
232+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
201233 expect ( Sentry . flush ) . toBeCalled ( ) ;
202234 }
203235 } ) ;
204236 } ) ;
205237
206238 describe ( 'wrapHandler() on async handler' , ( ) => {
207239 test ( 'successful execution' , async ( ) => {
208- expect . assertions ( 1 ) ;
240+ expect . assertions ( 5 ) ;
209241
210242 const handler : Handler = async ( _event , _context ) => {
211243 return 42 ;
212244 } ;
213245 const wrappedHandler = wrapHandler ( handler ) ;
214246 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
215247 expect ( rv ) . toStrictEqual ( 42 ) ;
248+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
249+ // @ts -ignore see "Why @ts-ignore" note
250+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
251+ // @ts -ignore see "Why @ts-ignore" note
252+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
253+ expect ( Sentry . flush ) . toBeCalled ( ) ;
216254 } ) ;
217255
218256 test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -227,7 +265,7 @@ describe('AWSLambda', () => {
227265 } ) ;
228266
229267 test ( 'capture error' , async ( ) => {
230- expect . assertions ( 2 ) ;
268+ expect . assertions ( 5 ) ;
231269
232270 const error = new Error ( 'wat' ) ;
233271 const handler : Handler = async ( _event , _context ) => {
@@ -238,22 +276,33 @@ describe('AWSLambda', () => {
238276 try {
239277 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
240278 } catch ( e ) {
241- expect ( Sentry . captureException ) . toBeCalled ( ) ;
279+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
280+ // @ts -ignore see "Why @ts-ignore" note
281+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
282+ expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
283+ // @ts -ignore see "Why @ts-ignore" note
284+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
242285 expect ( Sentry . flush ) . toBeCalled ( ) ;
243286 }
244287 } ) ;
245288 } ) ;
246289
247290 describe ( 'wrapHandler() on async handler with a callback method (aka incorrect usage)' , ( ) => {
248291 test ( 'successful execution' , async ( ) => {
249- expect . assertions ( 1 ) ;
292+ expect . assertions ( 5 ) ;
250293
251294 const handler : Handler = async ( _event , _context , _callback ) => {
252295 return 42 ;
253296 } ;
254297 const wrappedHandler = wrapHandler ( handler ) ;
255298 const rv = await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
256299 expect ( rv ) . toStrictEqual ( 42 ) ;
300+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
301+ // @ts -ignore see "Why @ts-ignore" note
302+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
303+ // @ts -ignore see "Why @ts-ignore" note
304+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
305+ expect ( Sentry . flush ) . toBeCalled ( ) ;
257306 } ) ;
258307
259308 test ( 'event and context are correctly passed to the original handler' , async ( ) => {
@@ -268,7 +317,7 @@ describe('AWSLambda', () => {
268317 } ) ;
269318
270319 test ( 'capture error' , async ( ) => {
271- expect . assertions ( 2 ) ;
320+ expect . assertions ( 5 ) ;
272321
273322 const error = new Error ( 'wat' ) ;
274323 const handler : Handler = async ( _event , _context , _callback ) => {
@@ -279,7 +328,12 @@ describe('AWSLambda', () => {
279328 try {
280329 await wrappedHandler ( fakeEvent , fakeContext , fakeCallback ) ;
281330 } catch ( e ) {
282- expect ( Sentry . captureException ) . toBeCalled ( ) ;
331+ expect ( Sentry . startTransaction ) . toBeCalledWith ( { name : 'functionName' , op : 'awslambda.handler' } ) ;
332+ // @ts -ignore see "Why @ts-ignore" note
333+ expect ( Sentry . fakeParentScope . setSpan ) . toBeCalledWith ( Sentry . fakeTransaction ) ;
334+ expect ( Sentry . captureException ) . toBeCalledWith ( error ) ;
335+ // @ts -ignore see "Why @ts-ignore" note
336+ expect ( Sentry . fakeTransaction . finish ) . toBeCalled ( ) ;
283337 expect ( Sentry . flush ) . toBeCalled ( ) ;
284338 }
285339 } ) ;
0 commit comments