Skip to content

Commit 6208e57

Browse files
authored
feat(core): Add default ignoreTransactions for Healthchecks (#8191)
Ignore health check transactions by default. Provide option to enable them via `InboundFilters` option `disableTransactionDefaults`. Ref: getsentry/team-webplatform-meta#70
1 parent 05cf332 commit 6208e57

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,25 @@ import { getEventDescription, logger, stringMatchesSomePattern } from '@sentry/u
55
// this is the result of a script being pulled in from an external domain and CORS.
66
const DEFAULT_IGNORE_ERRORS = [/^Script error\.?$/, /^Javascript error: Script error\.? on line 0$/];
77

8+
const DEFAULT_IGNORE_TRANSACTIONS = [
9+
/^.*healthcheck.*$/,
10+
/^.*healthy.*$/,
11+
/^.*live.*$/,
12+
/^.*ready.*$/,
13+
/^.*heartbeat.*$/,
14+
/^.*\/health$/,
15+
/^.*\/healthz$/,
16+
];
17+
818
/** Options for the InboundFilters integration */
919
export interface InboundFiltersOptions {
1020
allowUrls: Array<string | RegExp>;
1121
denyUrls: Array<string | RegExp>;
1222
ignoreErrors: Array<string | RegExp>;
1323
ignoreTransactions: Array<string | RegExp>;
1424
ignoreInternal: boolean;
25+
disableErrorDefaults: boolean;
26+
disableTransactionDefaults: boolean;
1527
}
1628

1729
/** Inbound filters configurable by the user */
@@ -62,9 +74,13 @@ export function _mergeOptions(
6274
ignoreErrors: [
6375
...(internalOptions.ignoreErrors || []),
6476
...(clientOptions.ignoreErrors || []),
65-
...DEFAULT_IGNORE_ERRORS,
77+
...(internalOptions.disableErrorDefaults ? [] : DEFAULT_IGNORE_ERRORS),
78+
],
79+
ignoreTransactions: [
80+
...(internalOptions.ignoreTransactions || []),
81+
...(clientOptions.ignoreTransactions || []),
82+
...(internalOptions.disableTransactionDefaults ? [] : DEFAULT_IGNORE_TRANSACTIONS),
6683
],
67-
ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])],
6884
ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true,
6985
};
7086
}

packages/core/test/lib/integrations/inboundfilters.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ const TRANSACTION_EVENT_3: Event = {
208208
type: 'transaction',
209209
};
210210

211+
const TRANSACTION_EVENT_HEALTH: Event = {
212+
transaction: 'GET /health',
213+
type: 'transaction',
214+
};
215+
216+
const TRANSACTION_EVENT_HEALTH_2: Event = {
217+
transaction: 'GET /healthy',
218+
type: 'transaction',
219+
};
220+
221+
const TRANSACTION_EVENT_HEALTH_3: Event = {
222+
transaction: 'GET /live',
223+
type: 'transaction',
224+
};
225+
211226
describe('InboundFilters', () => {
212227
describe('_isSentryError', () => {
213228
it('should work as expected', () => {
@@ -372,7 +387,28 @@ describe('InboundFilters', () => {
372387

373388
it('uses default filters', () => {
374389
const eventProcessor = createInboundFiltersEventProcessor();
390+
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null);
391+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(TRANSACTION_EVENT);
392+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(null);
393+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(null);
394+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(null);
395+
});
396+
397+
it('disable default error filters', () => {
398+
const eventProcessor = createInboundFiltersEventProcessor({ disableErrorDefaults: true });
399+
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(SCRIPT_ERROR_EVENT);
400+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(null);
401+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(null);
402+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(null);
403+
});
404+
405+
it('disable default transaction filters', () => {
406+
const eventProcessor = createInboundFiltersEventProcessor({ disableTransactionDefaults: true });
407+
expect(eventProcessor(SCRIPT_ERROR_EVENT, {})).toBe(null);
375408
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(TRANSACTION_EVENT);
409+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH, {})).toBe(TRANSACTION_EVENT_HEALTH);
410+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_2, {})).toBe(TRANSACTION_EVENT_HEALTH_2);
411+
expect(eventProcessor(TRANSACTION_EVENT_HEALTH_3, {})).toBe(TRANSACTION_EVENT_HEALTH_3);
376412
});
377413
});
378414

packages/nextjs/test/integration/test/client/tracingPageLoad.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Transaction } from '@sentry/types';
44

55
test('should report a `pageload` transaction', async ({ page }) => {
66
const transaction = await getMultipleSentryEnvelopeRequests<Transaction>(page, 1, {
7-
url: '/healthy',
7+
url: '/testy',
88
envelopeType: 'transaction',
99
});
1010

@@ -16,5 +16,5 @@ test('should report a `pageload` transaction', async ({ page }) => {
1616
},
1717
});
1818

19-
expect(await countEnvelopes(page, { url: '/healthy', envelopeType: 'transaction', timeout: 4000 })).toBe(1);
19+
expect(await countEnvelopes(page, { url: '/testy', envelopeType: 'transaction', timeout: 4000 })).toBe(1);
2020
});

0 commit comments

Comments
 (0)