diff --git a/packages/core/src/integrations/inboundfilters.ts b/packages/core/src/integrations/inboundfilters.ts index 998c7ab8203d..3b6b2e8933de 100644 --- a/packages/core/src/integrations/inboundfilters.ts +++ b/packages/core/src/integrations/inboundfilters.ts @@ -5,6 +5,16 @@ import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/u // this is the result of a script being pulled in from an external domain and CORS. const DEFAULT_IGNORE_ERRORS = [/^Script error\.?$/, /^Javascript error: Script error\.? on line 0$/]; +const DEFAULT_IGNORE_TRANSACTIONS = [ + /^.*healthcheck.*$/, + /^.*healthy.*$/, + /^.*live.*$/, + /^.*ready.*$/, + /^.*heartbeat.*$/, + /^.*\/health$/, + /^.*\/healthz$/, +]; + /** Options for the InboundFilters integration */ export interface InboundFiltersOptions { allowUrls: Array; @@ -12,6 +22,8 @@ export interface InboundFiltersOptions { ignoreErrors: Array; ignoreTransactions: Array; ignoreInternal: boolean; + disableErrorDefaults: boolean; + disableTransactionDefaults: boolean; } /** Inbound filters configurable by the user */ @@ -62,9 +74,13 @@ export function _mergeOptions( ignoreErrors: [ ...(internalOptions.ignoreErrors || []), ...(clientOptions.ignoreErrors || []), - ...DEFAULT_IGNORE_ERRORS, + ...(internalOptions.disableErrorDefaults ? [] : DEFAULT_IGNORE_ERRORS), + ], + ignoreTransactions: [ + ...(internalOptions.ignoreTransactions || []), + ...(clientOptions.ignoreTransactions || []), + ...(internalOptions.disableTransactionDefaults ? [] : DEFAULT_IGNORE_TRANSACTIONS), ], - ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])], ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true, }; } diff --git a/packages/core/test/lib/integrations/inboundfilters.test.ts b/packages/core/test/lib/integrations/inboundfilters.test.ts index a528d765bfeb..88ab23f65909 100644 --- a/packages/core/test/lib/integrations/inboundfilters.test.ts +++ b/packages/core/test/lib/integrations/inboundfilters.test.ts @@ -208,6 +208,21 @@ const TRANSACTION_EVENT_3: Event = { type: 'transaction', }; +const TRANSACTION_EVENT_HEALTH: Event = { + transaction: 'GET /health', + type: 'transaction', +}; + +const TRANSACTION_EVENT_HEALTH_2: Event = { + transaction: 'GET /healthy', + type: 'transaction', +}; + +const TRANSACTION_EVENT_HEALTH_3: Event = { + transaction: 'GET /live', + type: 'transaction', +}; + describe('InboundFilters', () => { describe('_isSentryError', () => { it('should work as expected', () => { @@ -372,7 +387,28 @@ describe('InboundFilters', () => { it('uses default filters', () => { const eventProcessor = createInboundFiltersEventProcessor(); + expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null); + expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(TRANSACTION_EVENT); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(null); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(null); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(null); + }); + + it('disable default error filters', () => { + const eventProcessor = createInboundFiltersEventProcessor({ disableErrorDefaults: true }); + expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(SCRIPT_ERROR_EVENT); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(null); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(null); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(null); + }); + + it('disable default transaction filters', () => { + const eventProcessor = createInboundFiltersEventProcessor({ disableTransactionDefaults: true }); + expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null); expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(TRANSACTION_EVENT); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(TRANSACTION_EVENT_HEALTH); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(TRANSACTION_EVENT_HEALTH_2); + expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(TRANSACTION_EVENT_HEALTH_3); }); }); diff --git a/packages/nextjs/test/integration/test/client/tracingPageLoad.test.ts b/packages/nextjs/test/integration/test/client/tracingPageLoad.test.ts index 028c8b2d7998..dc0f76d67644 100644 --- a/packages/nextjs/test/integration/test/client/tracingPageLoad.test.ts +++ b/packages/nextjs/test/integration/test/client/tracingPageLoad.test.ts @@ -4,7 +4,7 @@ import { Transaction } from '@sentry/types'; test('should report a `pageload` transaction', async ({ page }) => { const transaction = await getMultipleSentryEnvelopeRequests(page, 1, { - url: '/healthy', + url: '/testy', envelopeType: 'transaction', }); @@ -16,5 +16,5 @@ test('should report a `pageload` transaction', async ({ page }) => { }, }); - expect(await countEnvelopes(page, { url: '/healthy', envelopeType: 'transaction', timeout: 4000 })).toBe(1); + expect(await countEnvelopes(page, { url: '/testy', envelopeType: 'transaction', timeout: 4000 })).toBe(1); });