Skip to content

Commit

Permalink
feat(core): Add default ignoreTransactions for Healthchecks (#8191)
Browse files Browse the repository at this point in the history
Ignore health check transactions by default.
Provide option to enable them via `InboundFilters` option `disableTransactionDefaults`.

Ref: getsentry/team-webplatform-meta#70
  • Loading branch information
HazAT committed Jun 1, 2023
1 parent 05cf332 commit 6208e57
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 4 deletions.
20 changes: 18 additions & 2 deletions packages/core/src/integrations/inboundfilters.ts
Expand Up @@ -5,13 +5,25 @@ 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<string | RegExp>;
denyUrls: Array<string | RegExp>;
ignoreErrors: Array<string | RegExp>;
ignoreTransactions: Array<string | RegExp>;
ignoreInternal: boolean;
disableErrorDefaults: boolean;
disableTransactionDefaults: boolean;
}

/** Inbound filters configurable by the user */
Expand Down Expand Up @@ -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,
};
}
Expand Down
36 changes: 36 additions & 0 deletions packages/core/test/lib/integrations/inboundfilters.test.ts
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});

Expand Down
Expand Up @@ -4,7 +4,7 @@ import { Transaction } from '@sentry/types';

test('should report a `pageload` transaction', async ({ page }) => {
const transaction = await getMultipleSentryEnvelopeRequests<Transaction>(page, 1, {
url: '/healthy',
url: '/testy',
envelopeType: 'transaction',
});

Expand All @@ -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);
});

0 comments on commit 6208e57

Please sign in to comment.