@@ -63,10 +63,10 @@ export interface HttpServerSpansIntegrationOptions {
6363
6464 /**
6565 * 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) .
6767 * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes.
6868 *
69- * @default `[[401, 404], [300 , 399]]`
69+ * @default `[[401, 404], [301, 303], [305 , 399]]`
7070 */
7171 ignoreStatusCodes ?: ( number | [ number , number ] ) [ ] ;
7272
@@ -95,7 +95,9 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions
9595 const ignoreIncomingRequests = options . ignoreIncomingRequests ;
9696 const ignoreStatusCodes = options . ignoreStatusCodes ?? [
9797 [ 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 ] ,
99101 ] ;
100102
101103 const { onSpanCreated } = options ;
@@ -226,18 +228,12 @@ const _httpServerSpansIntegration = ((options: HttpServerSpansIntegrationOptions
226228 // Drop transaction if it has a status code that should be ignored
227229 if ( event . type === 'transaction' ) {
228230 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+ }
241237 }
242238 }
243239
@@ -394,3 +390,17 @@ function getIncomingRequestAttributesOnResponse(request: IncomingMessage, respon
394390
395391 return newAttributes ;
396392}
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