Skip to content

Commit 9bbc59a

Browse files
committed
address PR review
1 parent aab996f commit 9bbc59a

File tree

2 files changed

+52
-33
lines changed

2 files changed

+52
-33
lines changed

packages/core/src/integrations/inboundfilters.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export class InboundFilters implements Integration {
3535
/**
3636
* @inheritDoc
3737
*/
38-
public setupOnce(addGlobalEventProcessor: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
38+
public setupOnce(addGlobalEventProcessor: (processor: EventProcessor) => void, getCurrentHub: () => Hub): void {
3939
addGlobalEventProcessor((event: Event) => {
4040
const hub = getCurrentHub();
4141
if (hub) {
@@ -54,28 +54,32 @@ export class InboundFilters implements Integration {
5454

5555
/** JSDoc */
5656
export function _mergeOptions(
57-
intOptions: Partial<InboundFiltersOptions> = {},
57+
internalOptions: Partial<InboundFiltersOptions> = {},
5858
clientOptions: Partial<InboundFiltersOptions> = {},
5959
): Partial<InboundFiltersOptions> {
6060
return {
6161
allowUrls: [
6262
// eslint-disable-next-line deprecation/deprecation
63-
...(intOptions.whitelistUrls || []),
64-
...(intOptions.allowUrls || []),
63+
...(internalOptions.whitelistUrls || []),
64+
...(internalOptions.allowUrls || []),
6565
// eslint-disable-next-line deprecation/deprecation
6666
...(clientOptions.whitelistUrls || []),
6767
...(clientOptions.allowUrls || []),
6868
],
6969
denyUrls: [
7070
// eslint-disable-next-line deprecation/deprecation
71-
...(intOptions.blacklistUrls || []),
72-
...(intOptions.denyUrls || []),
71+
...(internalOptions.blacklistUrls || []),
72+
...(internalOptions.denyUrls || []),
7373
// eslint-disable-next-line deprecation/deprecation
7474
...(clientOptions.blacklistUrls || []),
7575
...(clientOptions.denyUrls || []),
7676
],
77-
ignoreErrors: [...(intOptions.ignoreErrors || []), ...(clientOptions.ignoreErrors || []), ...DEFAULT_IGNORE_ERRORS],
78-
ignoreInternal: typeof intOptions.ignoreInternal !== 'undefined' ? intOptions.ignoreInternal : true,
77+
ignoreErrors: [
78+
...(internalOptions.ignoreErrors || []),
79+
...(clientOptions.ignoreErrors || []),
80+
...DEFAULT_IGNORE_ERRORS,
81+
],
82+
ignoreInternal: internalOptions.ignoreInternal !== undefined ? internalOptions.ignoreInternal : true,
7983
};
8084
}
8185

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

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@ import { EventProcessor } from '@sentry/types';
22

33
import { InboundFilters, InboundFiltersOptions } from '../../../src/integrations/inboundfilters';
44

5-
/** JSDoc */
5+
/**
6+
* Creates an instance of the InboundFilters integration and returns
7+
* the event processor that the InboundFilters integration creates.
8+
*
9+
* To test the InboundFilters integration, call this function and assert on
10+
* how the event processor handles an event. For example, if you set up the
11+
* InboundFilters to filter out an SOME_EXCEPTION_EVENT.
12+
*
13+
* ```
14+
* // some options that cause SOME_EXCEPTION_EVENT to be filtered
15+
* const eventProcessor = createInboundFiltersEventProcessor(options);
16+
*
17+
* expect(eventProcessor(SOME_EXCEPTION_EVENT)).toBe(null);
18+
* ```
19+
*
20+
* @param options options passed into the InboundFilters integration
21+
* @param clientOptions options passed into the mock Sentry client
22+
*/
623
function createInboundFiltersEventProcessor(
724
options: Partial<InboundFiltersOptions> = {},
825
clientOptions: Partial<InboundFiltersOptions> = {},
926
): EventProcessor {
1027
const eventProcessors: EventProcessor[] = [];
11-
const inboundFilters = new InboundFilters(options);
28+
const inboundFiltersInstance = new InboundFilters(options);
1229

13-
function addGlobalEventProcessor(callback: EventProcessor): void {
14-
eventProcessors.push(callback);
30+
function addGlobalEventProcessor(processor: EventProcessor): void {
31+
eventProcessors.push(processor);
1532
expect(eventProcessors).toHaveLength(1);
1633
}
1734

1835
function getCurrentHub(): any {
1936
return {
2037
getIntegration(_integration: any): any {
2138
// pretend integration is enabled
22-
return inboundFilters;
39+
return inboundFiltersInstance;
2340
},
2441
getClient(): any {
2542
return {
@@ -29,13 +46,12 @@ function createInboundFiltersEventProcessor(
2946
};
3047
}
3148

32-
inboundFilters.setupOnce(addGlobalEventProcessor, getCurrentHub);
33-
49+
inboundFiltersInstance.setupOnce(addGlobalEventProcessor, getCurrentHub);
3450
return eventProcessors[0];
3551
}
3652

3753
describe('InboundFilters', () => {
38-
describe('isSentryError', () => {
54+
describe('_isSentryError', () => {
3955
it('should work as expected', () => {
4056
const eventProcessor = createInboundFiltersEventProcessor();
4157
expect(eventProcessor(MESSAGE_EVENT)).toBe(MESSAGE_EVENT);
@@ -81,7 +97,7 @@ describe('InboundFilters', () => {
8197
expect(eventProcessor(MESSAGE_EVENT_2)).toBe(MESSAGE_EVENT_2);
8298
});
8399

84-
it('uses message when both, message and exception are available', () => {
100+
it('prefers message when both message and exception are available', () => {
85101
const eventProcessor = createInboundFiltersEventProcessor({
86102
ignoreErrors: [/captureMessage/],
87103
});
@@ -102,11 +118,11 @@ describe('InboundFilters', () => {
102118

103119
it('uses default filters', () => {
104120
const eventProcessor = createInboundFiltersEventProcessor();
105-
expect(eventProcessor(DEFAULT_EVENT)).toBe(null);
121+
expect(eventProcessor(SCRIPT_ERROR_EVENT)).toBe(null);
106122
});
107123

108124
describe('on exception', () => {
109-
it('uses exceptions data when message is unavailable', () => {
125+
it('uses exception data when message is unavailable', () => {
110126
const eventProcessor = createInboundFiltersEventProcessor({
111127
ignoreErrors: ['SyntaxError: unidentified ? at line 1337'],
112128
});
@@ -131,19 +147,18 @@ describe('InboundFilters', () => {
131147

132148
describe('denyUrls/allowUrls', () => {
133149
it('should filter captured message based on its stack trace using string filter', () => {
134-
const eventProcessorBoth = createInboundFiltersEventProcessor({
135-
allowUrls: ['https://awesome-analytics.io'],
150+
const eventProcessorDeny = createInboundFiltersEventProcessor({
136151
denyUrls: ['https://awesome-analytics.io'],
137152
});
138-
expect(eventProcessorBoth(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
139-
const eventProcessorAllow = createInboundFiltersEventProcessor({
153+
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
154+
});
155+
156+
it('should allow denyUrls to take precedence', () => {
157+
const eventProcessorBoth = createInboundFiltersEventProcessor({
140158
allowUrls: ['https://awesome-analytics.io'],
141-
});
142-
expect(eventProcessorAllow(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(MESSAGE_EVENT_WITH_STACKTRACE);
143-
const eventProcessorDeny = createInboundFiltersEventProcessor({
144159
denyUrls: ['https://awesome-analytics.io'],
145160
});
146-
expect(eventProcessorDeny(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
161+
expect(eventProcessorBoth(MESSAGE_EVENT_WITH_STACKTRACE)).toBe(null);
147162
});
148163

149164
it('should filter captured message based on its stack trace using regexp filter', () => {
@@ -167,7 +182,7 @@ describe('InboundFilters', () => {
167182
expect(eventProcessor(EXCEPTION_EVENT_WITH_FRAMES)).toBe(null);
168183
});
169184

170-
it('should filter captured exceptions based on its stack trace using regexp filter', () => {
185+
it('should filter captured exception based on its stack trace using regexp filter', () => {
171186
const eventProcessor = createInboundFiltersEventProcessor({
172187
denyUrls: [/awesome-analytics\.io/],
173188
});
@@ -199,14 +214,14 @@ describe('InboundFilters', () => {
199214
const eventProcessor = createInboundFiltersEventProcessor({
200215
denyUrls: ['https://awesome-analytics.io/some/file.js'],
201216
});
202-
expect(eventProcessor(MESSAGE_EVENT_WITH_ANON_FRAME)).toBe(null);
217+
expect(eventProcessor(MESSAGE_EVENT_WITH_ANON_LAST_FRAME)).toBe(null);
203218
});
204219

205220
it('should search for script names when the last frame is from native code', () => {
206221
const eventProcessor = createInboundFiltersEventProcessor({
207222
denyUrls: ['https://awesome-analytics.io/some/file.js'],
208223
});
209-
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_FRAME)).toBe(null);
224+
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME)).toBe(null);
210225
});
211226
});
212227
});
@@ -234,7 +249,7 @@ const MESSAGE_EVENT_WITH_STACKTRACE = {
234249
},
235250
};
236251

237-
const MESSAGE_EVENT_WITH_ANON_FRAME = {
252+
const MESSAGE_EVENT_WITH_ANON_LAST_FRAME = {
238253
message: 'any',
239254
stacktrace: {
240255
frames: [
@@ -245,7 +260,7 @@ const MESSAGE_EVENT_WITH_ANON_FRAME = {
245260
},
246261
};
247262

248-
const MESSAGE_EVENT_WITH_NATIVE_FRAME = {
263+
const MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME = {
249264
message: 'any',
250265
stacktrace: {
251266
frames: [
@@ -296,7 +311,7 @@ const SENTRY_EVENT = {
296311
},
297312
};
298313

299-
const DEFAULT_EVENT = {
314+
const SCRIPT_ERROR_EVENT = {
300315
exception: {
301316
values: [
302317
{

0 commit comments

Comments
 (0)