Skip to content

Commit a062912

Browse files
authored
feat(core): Filter out error events with exception values and no stacktraces, values, or types (#12387)
1 parent 4009e3f commit a062912

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

packages/core/src/integrations/inboundfilters.ts

+28
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ function _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>)
7171
);
7272
return true;
7373
}
74+
if (_isUselessError(event)) {
75+
DEBUG_BUILD &&
76+
logger.warn(
77+
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
78+
event,
79+
)}`,
80+
);
81+
return true;
82+
}
7483
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
7584
DEBUG_BUILD &&
7685
logger.warn(
@@ -199,3 +208,22 @@ function _getEventFilterUrl(event: Event): string | null {
199208
return null;
200209
}
201210
}
211+
212+
function _isUselessError(event: Event): boolean {
213+
if (event.type) {
214+
// event is not an error
215+
return false;
216+
}
217+
218+
// We only want to consider events for dropping that actually have recorded exception values.
219+
if (!event.exception || !event.exception.values || event.exception.values.length === 0) {
220+
return false;
221+
}
222+
223+
return (
224+
// No top-level message
225+
!event.message &&
226+
// There are no exception values that have a stacktrace, a non-generic-Error type or value
227+
!event.exception.values.some(value => value.stacktrace || (value.type && value.type !== 'Error') || value.value)
228+
);
229+
}

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

+92
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,66 @@ const EXCEPTION_EVENT_WITH_LINKED_ERRORS: Event = {
165165
},
166166
};
167167

168+
const USELESS_EXCEPTION_EVENT: Event = {
169+
exception: {
170+
values: [
171+
{},
172+
{
173+
mechanism: { type: 'onunhandledrejection', handled: false },
174+
},
175+
],
176+
},
177+
};
178+
179+
const USELESS_ERROR_EXCEPTION_EVENT: Event = {
180+
exception: {
181+
values: [{ type: 'Error' }, {}],
182+
},
183+
};
184+
185+
const EVENT_WITH_MESSAGE: Event = {
186+
message: 'hello',
187+
};
188+
189+
const EVENT_WITH_STACKTRACE: Event = {
190+
exception: {
191+
values: [
192+
{},
193+
{
194+
stacktrace: {
195+
frames: [
196+
{
197+
abs_path: 'hello.js',
198+
},
199+
],
200+
},
201+
},
202+
],
203+
},
204+
};
205+
206+
const EVENT_WITH_TYPE: Event = {
207+
exception: {
208+
values: [
209+
{},
210+
{
211+
type: 'MyCustomError',
212+
},
213+
],
214+
},
215+
};
216+
217+
const EVENT_WITH_VALUE: Event = {
218+
exception: {
219+
values: [
220+
{},
221+
{
222+
value: 'some error',
223+
},
224+
],
225+
},
226+
};
227+
168228
const SENTRY_EVENT: Event = {
169229
exception: {
170230
values: [
@@ -511,4 +571,36 @@ describe('InboundFilters', () => {
511571
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME, {})).toBe(null);
512572
});
513573
});
574+
575+
describe('useless errors', () => {
576+
it("should drop event with exceptions that don't have any message, type or stack trace", () => {
577+
const eventProcessor = createInboundFiltersEventProcessor();
578+
expect(eventProcessor(USELESS_EXCEPTION_EVENT, {})).toBe(null);
579+
});
580+
581+
it('should drop event with just a generic error without stacktrace or message', () => {
582+
const eventProcessor = createInboundFiltersEventProcessor();
583+
expect(eventProcessor(USELESS_ERROR_EXCEPTION_EVENT, {})).toBe(null);
584+
});
585+
586+
it('should not drop event with a message', () => {
587+
const eventProcessor = createInboundFiltersEventProcessor();
588+
expect(eventProcessor(EVENT_WITH_MESSAGE, {})).toBe(EVENT_WITH_MESSAGE);
589+
});
590+
591+
it('should not drop event with an exception that has a type', () => {
592+
const eventProcessor = createInboundFiltersEventProcessor();
593+
expect(eventProcessor(EVENT_WITH_TYPE, {})).toBe(EVENT_WITH_TYPE);
594+
});
595+
596+
it('should not drop event with an exception that has a stacktrace', () => {
597+
const eventProcessor = createInboundFiltersEventProcessor();
598+
expect(eventProcessor(EVENT_WITH_STACKTRACE, {})).toBe(EVENT_WITH_STACKTRACE);
599+
});
600+
601+
it('should not drop event with an exception that has a value', () => {
602+
const eventProcessor = createInboundFiltersEventProcessor();
603+
expect(eventProcessor(EVENT_WITH_VALUE, {})).toBe(EVENT_WITH_VALUE);
604+
});
605+
});
514606
});

0 commit comments

Comments
 (0)