Skip to content

Commit 8d59db0

Browse files
authored
feat: Filter internal Sentry errors from transports/sdk (#1732)
1 parent 2aae895 commit 8d59db0

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
## Unreleased
4+
5+
- [core] feat: Filter internal Sentry errors from transports/sdk
6+
47
## 4.3.0
58

69
- [browser]: Move `ReportingObserver` integration to "pluggable" making it an opt-in integration

packages/core/src/integrations/inboundfilters.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ const DEFAULT_IGNORE_ERRORS = [/^Script error\.?$/, /^Javascript error: Script e
1212

1313
/** JSDoc */
1414
interface InboundFiltersOptions {
15-
ignoreErrors?: Array<string | RegExp>;
1615
blacklistUrls?: Array<string | RegExp>;
16+
ignoreErrors?: Array<string | RegExp>;
17+
ignoreInternal?: boolean;
1718
whitelistUrls?: Array<string | RegExp>;
1819
}
1920

@@ -54,6 +55,10 @@ export class InboundFilters implements Integration {
5455

5556
/** JSDoc */
5657
public shouldDropEvent(event: SentryEvent, options: InboundFiltersOptions): boolean {
58+
if (this.isSentryError(event, options)) {
59+
logger.warn(`Event dropped due to being internal Sentry Error.\nEvent: ${getEventDescription(event)}`);
60+
return true;
61+
}
5762
if (this.isIgnoredError(event, options)) {
5863
logger.warn(
5964
`Event dropped due to being matched by \`ignoreErrors\` option.\nEvent: ${getEventDescription(event)}`,
@@ -79,6 +84,20 @@ export class InboundFilters implements Integration {
7984
return false;
8085
}
8186

87+
/** JSDoc */
88+
public isSentryError(event: SentryEvent, options: InboundFiltersOptions = {}): boolean {
89+
if (!options.ignoreInternal) {
90+
return false;
91+
}
92+
93+
try {
94+
// tslint:disable-next-line:no-unsafe-any
95+
return (event as any).exception.values[0].type === 'SentryError';
96+
} catch (_oO) {
97+
return false;
98+
}
99+
}
100+
82101
/** JSDoc */
83102
public isIgnoredError(event: SentryEvent, options: InboundFiltersOptions = {}): boolean {
84103
if (!options.ignoreErrors || !options.ignoreErrors.length) {
@@ -120,6 +139,7 @@ export class InboundFilters implements Integration {
120139
...(clientOptions.ignoreErrors || []),
121140
...DEFAULT_IGNORE_ERRORS,
122141
],
142+
ignoreInternal: typeof this.options.ignoreInternal !== 'undefined' ? this.options.ignoreInternal : true,
123143
whitelistUrls: [...(this.options.whitelistUrls || []), ...(clientOptions.whitelistUrls || [])],
124144
};
125145
}

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ describe('InboundFilters', () => {
88
});
99

1010
describe('shouldDropEvent', () => {
11+
it('should drop when error is internal one', () => {
12+
inboundFilters.isSentryError = () => true;
13+
expect(inboundFilters.shouldDropEvent({}, inboundFilters.mergeOptions())).toBe(true);
14+
});
15+
1116
it('should drop when error is ignored', () => {
1217
inboundFilters.isIgnoredError = () => true;
1318
expect(inboundFilters.shouldDropEvent({}, inboundFilters.mergeOptions())).toBe(true);
@@ -49,6 +54,47 @@ describe('InboundFilters', () => {
4954
});
5055
});
5156

57+
describe('isSentryError', () => {
58+
const messageEvent = {
59+
message: 'captureMessage',
60+
};
61+
const exceptionEvent = {
62+
exception: {
63+
values: [
64+
{
65+
type: 'SyntaxError',
66+
value: 'unidentified ? at line 1337',
67+
},
68+
],
69+
},
70+
};
71+
const sentryEvent = {
72+
exception: {
73+
values: [
74+
{
75+
type: 'SentryError',
76+
value: 'something something server connection',
77+
},
78+
],
79+
},
80+
};
81+
82+
it('should work as expected', () => {
83+
expect(inboundFilters.isSentryError(messageEvent, inboundFilters.mergeOptions())).toBe(false);
84+
expect(inboundFilters.isSentryError(exceptionEvent, inboundFilters.mergeOptions())).toBe(false);
85+
expect(inboundFilters.isSentryError(sentryEvent, inboundFilters.mergeOptions())).toBe(true);
86+
});
87+
88+
it('should be configurable', () => {
89+
inboundFilters = new InboundFilters({
90+
ignoreInternal: false,
91+
});
92+
expect(inboundFilters.isSentryError(messageEvent, inboundFilters.mergeOptions())).toBe(false);
93+
expect(inboundFilters.isSentryError(exceptionEvent, inboundFilters.mergeOptions())).toBe(false);
94+
expect(inboundFilters.isSentryError(sentryEvent, inboundFilters.mergeOptions())).toBe(false);
95+
});
96+
});
97+
5298
describe('ignoreErrors', () => {
5399
const messageEvent = {
54100
message: 'captureMessage',

0 commit comments

Comments
 (0)