Skip to content

Commit e04f7bb

Browse files
committed
adjust changes
1 parent 8e3d107 commit e04f7bb

File tree

3 files changed

+26
-45
lines changed

3 files changed

+26
-45
lines changed

packages/node-core/src/integrations/http/httpServerSpansIntegration.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

packages/node-core/src/integrations/http/index.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,3 @@ export const httpIntegration = defineIntegration((options: HttpOptions = {}) =>
176176
},
177177
};
178178
});
179-
180-
/**
181-
* If the given status code should be filtered for the given list of status codes/ranges.
182-
*/
183-
function shouldFilterStatusCode(statusCode: number, dropForStatusCodes: (number | [number, number])[]): boolean {
184-
return dropForStatusCodes.some(code => {
185-
if (typeof code === 'number') {
186-
return code === statusCode;
187-
}
188-
189-
const [min, max] = code;
190-
return statusCode >= min && statusCode <= max;
191-
});
192-
}

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { diag } from '@opentelemetry/api';
33
import type { HttpInstrumentationConfig } from '@opentelemetry/instrumentation-http';
44
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
55
import type { Span } from '@sentry/core';
6-
import { debug, defineIntegration, getClient, hasSpansEnabled } from '@sentry/core';
6+
import { defineIntegration, getClient, hasSpansEnabled } from '@sentry/core';
77
import type { HTTPModuleRequestIncomingMessage, NodeClient } from '@sentry/node-core';
88
import {
99
type SentryHttpInstrumentationOptions,
@@ -15,7 +15,6 @@ import {
1515
NODE_VERSION,
1616
SentryHttpInstrumentation,
1717
} from '@sentry/node-core';
18-
import { DEBUG_BUILD } from '../debug-build';
1918
import type { NodeClientOptions } from '../types';
2019

2120
const INTEGRATION_NAME = 'Http';
@@ -302,17 +301,3 @@ function getConfigWithDefaults(options: Partial<HttpOptions> = {}): HttpInstrume
302301

303302
return instrumentationConfig;
304303
}
305-
306-
/**
307-
* If the given status code should be filtered for the given list of status codes/ranges.
308-
*/
309-
function shouldFilterStatusCode(statusCode: number, dropForStatusCodes: (number | [number, number])[]): boolean {
310-
return dropForStatusCodes.some(code => {
311-
if (typeof code === 'number') {
312-
return code === statusCode;
313-
}
314-
315-
const [min, max] = code;
316-
return statusCode >= min && statusCode <= max;
317-
});
318-
}

0 commit comments

Comments
 (0)