From e5403464d8d199c6bc28084a7f57137d907d8e3d Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Sep 2025 14:20:41 +0200 Subject: [PATCH 1/5] feat(node): Do not drop 300, 302 and 304 status codes by default --- .../node-core/src/integrations/http/index.ts | 44 ++++++++++++------- packages/node/src/integrations/http.ts | 44 ++++++++++++------- 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/packages/node-core/src/integrations/http/index.ts b/packages/node-core/src/integrations/http/index.ts index 8f81f28c8eb6..3dc5dbe69647 100644 --- a/packages/node-core/src/integrations/http/index.ts +++ b/packages/node-core/src/integrations/http/index.ts @@ -1,5 +1,6 @@ import type { IncomingMessage, RequestOptions } from 'node:http'; -import { defineIntegration } from '@sentry/core'; +import { debug, defineIntegration } from '@sentry/core'; +import { DEBUG_BUILD } from '../../debug-build'; import { generateInstrumentOnce } from '../../otel/instrument'; import type { SentryHttpInstrumentationOptions } from './SentryHttpInstrumentation'; import { SentryHttpInstrumentation } from './SentryHttpInstrumentation'; @@ -62,10 +63,10 @@ interface HttpOptions { /** * Do not capture spans for incoming HTTP requests with the given status codes. - * By default, spans with 404 status code are ignored. + * By default, spans with some 3xx and 4xx status codes are ignored. * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * - * @default `[[401, 404], [300, 399]]` + * @default `[[401, 404], 301, 303, [305, 399]]` */ dropSpansForIncomingRequestStatusCodes?: (number | [number, number])[]; @@ -115,7 +116,10 @@ export const instrumentSentryHttp = generateInstrumentOnce { const dropSpansForIncomingRequestStatusCodes = options.dropSpansForIncomingRequestStatusCodes ?? [ [401, 404], - [300, 399], + // 300, 302 and 304 are possibly valid status codes we do not want to filter + 301, + 303, + [305, 399], ]; return { @@ -133,18 +137,12 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) => // Drop transaction if it has a status code that should be ignored if (event.type === 'transaction') { const statusCode = event.contexts?.trace?.data?.['http.response.status_code']; - if ( - typeof statusCode === 'number' && - dropSpansForIncomingRequestStatusCodes.some(code => { - if (typeof code === 'number') { - return code === statusCode; - } - - const [min, max] = code; - return statusCode >= min && statusCode <= max; - }) - ) { - return null; + if (typeof statusCode === 'number') { + const shouldDrop = shouldFilterStatusCode(statusCode, dropSpansForIncomingRequestStatusCodes); + if (shouldDrop) { + DEBUG_BUILD && debug.log('Dropping transaction due to status code', statusCode); + return null; + } } } @@ -152,3 +150,17 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) => }, }; }); + +/** + * If the given status code should be filtered for the given list of status codes/ranges. + */ +function shouldFilterStatusCode(statusCode: number, dropForStatusCodes: (number | [number, number])[]): boolean { + return dropForStatusCodes.some(code => { + if (typeof code === 'number') { + return code === statusCode; + } + + const [min, max] = code; + return statusCode >= min && statusCode <= max; + }); +} diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 60999b108872..1bc2692d6c68 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -3,7 +3,7 @@ import { diag } from '@opentelemetry/api'; import type { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http'; import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; import type { Span } from '@sentry/core'; -import { defineIntegration, getClient, hasSpansEnabled } from '@sentry/core'; +import { debug, defineIntegration, getClient, hasSpansEnabled } from '@sentry/core'; import type { HTTPModuleRequestIncomingMessage, NodeClient } from '@sentry/node-core'; import { type SentryHttpInstrumentationOptions, @@ -13,6 +13,7 @@ import { NODE_VERSION, SentryHttpInstrumentation, } from '@sentry/node-core'; +import { DEBUG_BUILD } from '../debug-build'; import type { NodeClientOptions } from '../types'; const INTEGRATION_NAME = 'Http'; @@ -84,10 +85,10 @@ interface HttpOptions { /** * Do not capture spans for incoming HTTP requests with the given status codes. - * By default, spans with 404 status code are ignored. + * By default, spans with some 3xx and 4xx status codes are ignored. * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * - * @default `[[401, 404], [300, 399]]` + * @default `[[401, 404], 301, 303, [305, 399]]` */ dropSpansForIncomingRequestStatusCodes?: (number | [number, number])[]; @@ -195,7 +196,10 @@ export function _shouldUseOtelHttpInstrumentation( export const httpIntegration = defineIntegration((options: HttpOptions = {}) => { const dropSpansForIncomingRequestStatusCodes = options.dropSpansForIncomingRequestStatusCodes ?? [ [401, 404], - [300, 399], + // 300, 302 and 304 are possibly valid status codes we do not want to filter + 301, + 303, + [305, 399], ]; return { @@ -225,18 +229,12 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) => // Drop transaction if it has a status code that should be ignored if (event.type === 'transaction') { const statusCode = event.contexts?.trace?.data?.['http.response.status_code']; - if ( - typeof statusCode === 'number' && - dropSpansForIncomingRequestStatusCodes.some(code => { - if (typeof code === 'number') { - return code === statusCode; - } - - const [min, max] = code; - return statusCode >= min && statusCode <= max; - }) - ) { - return null; + if (typeof statusCode === 'number') { + const shouldDrop = shouldFilterStatusCode(statusCode, dropSpansForIncomingRequestStatusCodes); + if (shouldDrop) { + DEBUG_BUILD && debug.log('Dropping transaction due to status code', statusCode); + return null; + } } } @@ -282,3 +280,17 @@ function getConfigWithDefaults(options: Partial = {}): HttpInstrume return instrumentationConfig; } + +/** + * If the given status code should be filtered for the given list of status codes/ranges. + */ +function shouldFilterStatusCode(statusCode: number, dropForStatusCodes: (number | [number, number])[]): boolean { + return dropForStatusCodes.some(code => { + if (typeof code === 'number') { + return code === statusCode; + } + + const [min, max] = code; + return statusCode >= min && statusCode <= max; + }); +} From 74bd777999e6c131b13fb5328d89d13cf8adfcff Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Sep 2025 14:41:26 +0200 Subject: [PATCH 2/5] ignore 302 --- packages/node-core/src/integrations/http/index.ts | 5 ++--- packages/node/src/integrations/http.ts | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/node-core/src/integrations/http/index.ts b/packages/node-core/src/integrations/http/index.ts index 3dc5dbe69647..4f864d4749b0 100644 --- a/packages/node-core/src/integrations/http/index.ts +++ b/packages/node-core/src/integrations/http/index.ts @@ -116,9 +116,8 @@ export const instrumentSentryHttp = generateInstrumentOnce { const dropSpansForIncomingRequestStatusCodes = options.dropSpansForIncomingRequestStatusCodes ?? [ [401, 404], - // 300, 302 and 304 are possibly valid status codes we do not want to filter - 301, - 303, + // 300 and 304 are possibly valid status codes we do not want to filter + [301, 303], [305, 399], ]; diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 1bc2692d6c68..3b608f8acf10 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -196,9 +196,8 @@ export function _shouldUseOtelHttpInstrumentation( export const httpIntegration = defineIntegration((options: HttpOptions = {}) => { const dropSpansForIncomingRequestStatusCodes = options.dropSpansForIncomingRequestStatusCodes ?? [ [401, 404], - // 300, 302 and 304 are possibly valid status codes we do not want to filter - 301, - 303, + // 300 and 304 are possibly valid status codes we do not want to filter + [301, 303], [305, 399], ]; From f70e93df44270a5ba0527f8fd2fea57976ab4f67 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Sep 2025 14:57:38 +0200 Subject: [PATCH 3/5] reference defaults --- packages/node-core/src/integrations/http/index.ts | 2 +- packages/node/src/integrations/http.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/node-core/src/integrations/http/index.ts b/packages/node-core/src/integrations/http/index.ts index 4f864d4749b0..f199acef3c3e 100644 --- a/packages/node-core/src/integrations/http/index.ts +++ b/packages/node-core/src/integrations/http/index.ts @@ -63,7 +63,7 @@ interface HttpOptions { /** * Do not capture spans for incoming HTTP requests with the given status codes. - * By default, spans with some 3xx and 4xx status codes are ignored. + * By default, spans with some 3xx and 4xx status codes are ignored (see @default). * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * * @default `[[401, 404], 301, 303, [305, 399]]` diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index 3b608f8acf10..d5c676de288a 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -85,7 +85,7 @@ interface HttpOptions { /** * Do not capture spans for incoming HTTP requests with the given status codes. - * By default, spans with some 3xx and 4xx status codes are ignored. + * By default, spans with some 3xx and 4xx status codes are ignored (see @default). * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * * @default `[[401, 404], 301, 303, [305, 399]]` @@ -144,6 +144,7 @@ export const instrumentSentryHttp = generateInstrumentOnce(INTEGRATION_NAME, config => { const instrumentation = new HttpInstrumentation({ ...config, From 9146ae2c6fdd9cb40bd59b39968279e045b6de58 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Sep 2025 14:57:58 +0200 Subject: [PATCH 4/5] fix defaults --- packages/node-core/src/integrations/http/index.ts | 2 +- packages/node/src/integrations/http.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/node-core/src/integrations/http/index.ts b/packages/node-core/src/integrations/http/index.ts index f199acef3c3e..e89af730302d 100644 --- a/packages/node-core/src/integrations/http/index.ts +++ b/packages/node-core/src/integrations/http/index.ts @@ -66,7 +66,7 @@ interface HttpOptions { * By default, spans with some 3xx and 4xx status codes are ignored (see @default). * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * - * @default `[[401, 404], 301, 303, [305, 399]]` + * @default `[[401, 404], [301, 303], [305, 399]]` */ dropSpansForIncomingRequestStatusCodes?: (number | [number, number])[]; diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index d5c676de288a..e613947c72eb 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -88,7 +88,7 @@ interface HttpOptions { * By default, spans with some 3xx and 4xx status codes are ignored (see @default). * Expects an array of status codes or a range of status codes, e.g. [[300,399], 404] would ignore 3xx and 404 status codes. * - * @default `[[401, 404], 301, 303, [305, 399]]` + * @default `[[401, 404], [301, 303], [305, 399]]` */ dropSpansForIncomingRequestStatusCodes?: (number | [number, number])[]; From b03fe80fcb3b99914a77895f717b92b76bd36bdf Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 17 Sep 2025 15:05:17 +0200 Subject: [PATCH 5/5] fix lint --- packages/node/src/integrations/http.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index e613947c72eb..dc7b48b4862c 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -144,7 +144,6 @@ export const instrumentSentryHttp = generateInstrumentOnce(INTEGRATION_NAME, config => { const instrumentation = new HttpInstrumentation({ ...config,