@@ -77,7 +77,7 @@ describe('express v5 tracing', () => {
77
77
await runner . completed ( ) ;
78
78
} ) ;
79
79
80
- test ( 'handles root page correctly' , async ( ) => {
80
+ test ( 'handles root route correctly' , async ( ) => {
81
81
const runner = createRunner ( )
82
82
. expect ( {
83
83
transaction : {
@@ -89,30 +89,17 @@ describe('express v5 tracing', () => {
89
89
await runner . completed ( ) ;
90
90
} ) ;
91
91
92
- test ( 'handles 404 page correctly ' , async ( ) => {
92
+ test ( 'ignores 404 routes by default ' , async ( ) => {
93
93
const runner = createRunner ( )
94
94
. expect ( {
95
+ // No transaction is sent for the 404 route
95
96
transaction : {
96
- transaction : 'GET /does-not-exist' ,
97
- contexts : {
98
- trace : {
99
- span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
100
- trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
101
- data : {
102
- 'http.response.status_code' : 404 ,
103
- url : expect . stringMatching ( / \/ d o e s - n o t - e x i s t $ / ) ,
104
- 'http.method' : 'GET' ,
105
- 'http.url' : expect . stringMatching ( / \/ d o e s - n o t - e x i s t $ / ) ,
106
- 'http.target' : '/does-not-exist' ,
107
- } ,
108
- op : 'http.server' ,
109
- status : 'not_found' ,
110
- } ,
111
- } ,
97
+ transaction : 'GET /' ,
112
98
} ,
113
99
} )
114
100
. start ( ) ;
115
101
runner . makeRequest ( 'get' , '/does-not-exist' , { expectError : true } ) ;
102
+ runner . makeRequest ( 'get' , '/' ) ;
116
103
await runner . completed ( ) ;
117
104
} ) ;
118
105
@@ -290,4 +277,56 @@ describe('express v5 tracing', () => {
290
277
} ) ;
291
278
} ) ;
292
279
} ) ;
280
+
281
+ describe ( 'filter status codes' , ( ) => {
282
+ createEsmAndCjsTests (
283
+ __dirname ,
284
+ 'scenario-filterStatusCode.mjs' ,
285
+ 'instrument-filterStatusCode.mjs' ,
286
+ ( createRunner , test ) => {
287
+ // We opt-out of the default 404 filtering in order to test how 404 spans are handled
288
+ test ( 'handles 404 route correctly' , async ( ) => {
289
+ const runner = createRunner ( )
290
+ . expect ( {
291
+ transaction : {
292
+ transaction : 'GET /does-not-exist' ,
293
+ contexts : {
294
+ trace : {
295
+ span_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 16 } / ) ,
296
+ trace_id : expect . stringMatching ( / [ a - f 0 - 9 ] { 32 } / ) ,
297
+ data : {
298
+ 'http.response.status_code' : 404 ,
299
+ url : expect . stringMatching ( / \/ d o e s - n o t - e x i s t $ / ) ,
300
+ 'http.method' : 'GET' ,
301
+ 'http.url' : expect . stringMatching ( / \/ d o e s - n o t - e x i s t $ / ) ,
302
+ 'http.target' : '/does-not-exist' ,
303
+ } ,
304
+ op : 'http.server' ,
305
+ status : 'not_found' ,
306
+ } ,
307
+ } ,
308
+ } ,
309
+ } )
310
+ . start ( ) ;
311
+ runner . makeRequest ( 'get' , '/does-not-exist' , { expectError : true } ) ;
312
+ await runner . completed ( ) ;
313
+ } ) ;
314
+
315
+ test ( 'filters defined status codes' , async ( ) => {
316
+ const runner = createRunner ( )
317
+ . expect ( {
318
+ transaction : {
319
+ transaction : 'GET /' ,
320
+ } ,
321
+ } )
322
+ . start ( ) ;
323
+ await runner . makeRequest ( 'get' , '/499' , { expectError : true } ) ;
324
+ await runner . makeRequest ( 'get' , '/300' , { expectError : true } ) ;
325
+ await runner . makeRequest ( 'get' , '/399' , { expectError : true } ) ;
326
+ await runner . makeRequest ( 'get' , '/' ) ;
327
+ await runner . completed ( ) ;
328
+ } ) ;
329
+ } ,
330
+ ) ;
331
+ } ) ;
293
332
} ) ;
0 commit comments