@@ -63,10 +63,10 @@ export interface HttpServerSpansIntegrationOptions {
63
63
64
64
/**
65
65
* Do not capture spans for incoming HTTP requests with the given status codes.
66
- * By default, spans with 404 status code are ignored.
66
+ * By default, spans with some 3xx and 4xx status codes are ignored (see @default) .
67
67
* Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes.
68
68
*
69
- * @default `[[401, 404], [300 , 399]]`
69
+ * @default `[[401, 404], [301, 303], [305 , 399]]`
70
70
*/
71
71
ignoreStatusCodes ?: ( number | [ number , number ] ) [ ] ;
72
72
@@ -95,7 +95,9 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions
95
95
const ignoreIncomingRequests = options . ignoreIncomingRequests ;
96
96
const ignoreStatusCodes = options . ignoreStatusCodes ?? [
97
97
[ 401 , 404 ] ,
98
- [ 300 , 399 ] ,
98
+ // 300 and 304 are possibly valid status codes we do not want to filter
99
+ [ 301 , 303 ] ,
100
+ [ 305 , 399 ] ,
99
101
] ;
100
102
101
103
const { onSpanCreated } = options ;
@@ -226,18 +228,12 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions
226
228
// Drop transaction if it has a status code that should be ignored
227
229
if ( event . type === 'transaction' ) {
228
230
const statusCode = event . contexts ?. trace ?. data ?. [ 'http.response.status_code' ] ;
229
- if (
230
- typeof statusCode === 'number' &&
231
- ignoreStatusCodes . some ( code => {
232
- if ( typeof code === 'number' ) {
233
- return code === statusCode ;
234
- }
235
-
236
- const [ min , max ] = code ;
237
- return statusCode >= min && statusCode <= max ;
238
- } )
239
- ) {
240
- return null ;
231
+ if ( typeof statusCode === 'number' ) {
232
+ const shouldDrop = shouldFilterStatusCode ( statusCode , ignoreStatusCodes ) ;
233
+ if ( shouldDrop ) {
234
+ DEBUG_BUILD && debug . log ( 'Dropping transaction due to status code' , statusCode ) ;
235
+ return null ;
236
+ }
241
237
}
242
238
}
243
239
@@ -394,3 +390,17 @@ function getIncomingRequestAttributesOnResponse(request: IncomingMessage, respon
394
390
395
391
return newAttributes ;
396
392
}
393
+
394
+ /**
395
+ * If the given status code should be filtered for the given list of status codes/ranges.
396
+ */
397
+ function shouldFilterStatusCode ( statusCode : number , dropForStatusCodes : ( number | [ number , number ] ) [ ] ) : boolean {
398
+ return dropForStatusCodes . some ( code => {
399
+ if ( typeof code === 'number' ) {
400
+ return code === statusCode ;
401
+ }
402
+
403
+ const [ min , max ] = code ;
404
+ return statusCode >= min && statusCode <= max ;
405
+ } ) ;
406
+ }
0 commit comments