Skip to content

Commit 3ba8265

Browse files
authored
feat(core): Add ignoreTransactions option (#7594)
This works similar to `ignoreErrors`, but matches transaction names.
1 parent d330c2f commit 3ba8265

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface InboundFiltersOptions {
1010
allowUrls: Array<string | RegExp>;
1111
denyUrls: Array<string | RegExp>;
1212
ignoreErrors: Array<string | RegExp>;
13+
ignoreTransactions: Array<string | RegExp>;
1314
ignoreInternal: boolean;
1415
}
1516

@@ -63,6 +64,7 @@ export function _mergeOptions(
6364
...(clientOptions.ignoreErrors || []),
6465
...DEFAULT_IGNORE_ERRORS,
6566
],
67+
ignoreTransactions: [...(internalOptions.ignoreTransactions || []), ...(clientOptions.ignoreTransactions || [])],
6668
ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true,
6769
};
6870
}
@@ -81,6 +83,13 @@ export function _shouldDropEvent(event: Event, options: Partial<InboundFiltersOp
8183
);
8284
return true;
8385
}
86+
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
87+
__DEBUG_BUILD__ &&
88+
logger.warn(
89+
`Event dropped due to being matched by \`ignoreTransactions\` option.\nEvent: ${getEventDescription(event)}`,
90+
);
91+
return true;
92+
}
8493
if (_isDeniedUrl(event, options.denyUrls)) {
8594
__DEBUG_BUILD__ &&
8695
logger.warn(
@@ -111,6 +120,15 @@ function _isIgnoredError(event: Event, ignoreErrors?: Array<string | RegExp>): b
111120
return _getPossibleEventMessages(event).some(message => stringMatchesSomePattern(message, ignoreErrors));
112121
}
113122

123+
function _isIgnoredTransaction(event: Event, ignoreTransactions?: Array<string | RegExp>): boolean {
124+
if (event.type !== 'transaction' || !ignoreTransactions || !ignoreTransactions.length) {
125+
return false;
126+
}
127+
128+
const name = event.transaction;
129+
return name ? stringMatchesSomePattern(name, ignoreTransactions) : false;
130+
}
131+
114132
function _isDeniedUrl(event: Event, denyUrls?: Array<string | RegExp>): boolean {
115133
// TODO: Use Glob instead?
116134
if (!denyUrls || !denyUrls.length) {

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

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@ const MALFORMED_EVENT: Event = {
179179

180180
const TRANSACTION_EVENT: Event = {
181181
message: 'transaction message',
182+
transaction: 'transaction name',
183+
type: 'transaction',
184+
};
185+
186+
const TRANSACTION_EVENT_2: Event = {
187+
transaction: 'transaction name 2',
188+
type: 'transaction',
189+
};
190+
191+
const TRANSACTION_EVENT_3: Event = {
192+
transaction: 'other name',
182193
type: 'transaction',
183194
};
184195

@@ -284,6 +295,58 @@ describe('InboundFilters', () => {
284295
});
285296
});
286297

298+
describe('ignoreTransactions', () => {
299+
it('string filter with partial match', () => {
300+
const eventProcessor = createInboundFiltersEventProcessor({
301+
ignoreTransactions: ['name'],
302+
});
303+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(null);
304+
});
305+
306+
it('ignores error event for filtering', () => {
307+
const eventProcessor = createInboundFiltersEventProcessor({
308+
ignoreTransactions: ['capture'],
309+
});
310+
expect(eventProcessor(MESSAGE_EVENT, {})).toBe(MESSAGE_EVENT);
311+
});
312+
313+
it('string filter with exact match', () => {
314+
const eventProcessor = createInboundFiltersEventProcessor({
315+
ignoreTransactions: ['transaction name'],
316+
});
317+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(null);
318+
});
319+
320+
it('regexp filter with partial match', () => {
321+
const eventProcessor = createInboundFiltersEventProcessor({
322+
ignoreTransactions: [/name/],
323+
});
324+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(null);
325+
});
326+
327+
it('regexp filter with exact match', () => {
328+
const eventProcessor = createInboundFiltersEventProcessor({
329+
ignoreTransactions: [/^transaction name$/],
330+
});
331+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(null);
332+
expect(eventProcessor(TRANSACTION_EVENT_2, {})).toBe(TRANSACTION_EVENT_2);
333+
});
334+
335+
it('can use multiple filters', () => {
336+
const eventProcessor = createInboundFiltersEventProcessor({
337+
ignoreTransactions: ['transaction name 2', /transaction/],
338+
});
339+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(null);
340+
expect(eventProcessor(TRANSACTION_EVENT_2, {})).toBe(null);
341+
expect(eventProcessor(TRANSACTION_EVENT_3, {})).toBe(TRANSACTION_EVENT_3);
342+
});
343+
344+
it('uses default filters', () => {
345+
const eventProcessor = createInboundFiltersEventProcessor();
346+
expect(eventProcessor(TRANSACTION_EVENT, {})).toBe(TRANSACTION_EVENT);
347+
});
348+
});
349+
287350
describe('denyUrls/allowUrls', () => {
288351
it('should filter captured message based on its stack trace using string filter', () => {
289352
const eventProcessorDeny = createInboundFiltersEventProcessor({

packages/types/src/options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ export interface ClientOptions<TO extends BaseTransportOptions = BaseTransportOp
162162
*/
163163
ignoreErrors?: Array<string | RegExp>;
164164

165+
/**
166+
* A pattern for transaction names which should not be sent to Sentry.
167+
* By default, all transactions will be sent.
168+
*/
169+
ignoreTransactions?: Array<string | RegExp>;
170+
165171
/**
166172
* A URL to an envelope tunnel endpoint. An envelope tunnel is an HTTP endpoint
167173
* that accepts Sentry envelopes for forwarding. This can be used to force data

0 commit comments

Comments
 (0)