Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Filter out error events with exception values and no stacktraces, values, or types #12387

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/core/src/integrations/inboundfilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ function _shouldDropEvent(event: Event, options: Partial<InboundFiltersOptions>)
);
return true;
}
if (_isUselessError(event)) {
DEBUG_BUILD &&
logger.warn(
`Event dropped due to not having an error message, error type or stacktrace.\nEvent: ${getEventDescription(
event,
)}`,
);
return true;
}
if (_isIgnoredTransaction(event, options.ignoreTransactions)) {
DEBUG_BUILD &&
logger.warn(
Expand Down Expand Up @@ -195,3 +204,22 @@ function _getEventFilterUrl(event: Event): string | null {
return null;
}
}

function _isUselessError(event: Event): boolean {
if (event.type) {
// event is not an error
return false;
}

// We only want to consider events for dropping that actually have recorded exception values.
if (!event.exception || !event.exception.values || event.exception.values.length === 0) {
return false;
}

return (
// No top-level message
!event.message &&
// There are no exception values that have a stacktrace, a non-generic-Error type or value
!event.exception.values.some(value => value.stacktrace || (value.type && value.type !== 'Error') || value.value)
);
}
92 changes: 92 additions & 0 deletions packages/core/test/lib/integrations/inboundfilters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,66 @@ const EXCEPTION_EVENT_WITH_LINKED_ERRORS: Event = {
},
};

const USELESS_EXCEPTION_EVENT: Event = {
exception: {
values: [
{},
{
mechanism: { type: 'onunhandledrejection', handled: false },
},
],
},
};

const USELESS_ERROR_EXCEPTION_EVENT: Event = {
exception: {
values: [{ type: 'Error' }, {}],
},
};

const EVENT_WITH_MESSAGE: Event = {
message: 'hello',
};

const EVENT_WITH_STACKTRACE: Event = {
exception: {
values: [
{},
{
stacktrace: {
frames: [
{
abs_path: 'hello.js',
},
],
},
},
],
},
};

const EVENT_WITH_TYPE: Event = {
exception: {
values: [
{},
{
type: 'MyCustomError',
},
],
},
};

const EVENT_WITH_VALUE: Event = {
exception: {
values: [
{},
{
value: 'some error',
},
],
},
};

const SENTRY_EVENT: Event = {
exception: {
values: [
Expand Down Expand Up @@ -511,4 +571,36 @@ describe('InboundFilters', () => {
expect(eventProcessor(MESSAGE_EVENT_WITH_NATIVE_LAST_FRAME, {})).toBe(null);
});
});

describe('useless errors', () => {
it("should drop event with exceptions that don't have any message, type or stack trace", () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(USELESS_EXCEPTION_EVENT, {})).toBe(null);
});

it('should drop event with just a generic error without stacktrace or message', () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(USELESS_ERROR_EXCEPTION_EVENT, {})).toBe(null);
});

it('should not drop event with a message', () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(EVENT_WITH_MESSAGE, {})).toBe(EVENT_WITH_MESSAGE);
});

it('should not drop event with an exception that has a type', () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(EVENT_WITH_TYPE, {})).toBe(EVENT_WITH_TYPE);
});

it('should not drop event with an exception that has a stacktrace', () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(EVENT_WITH_STACKTRACE, {})).toBe(EVENT_WITH_STACKTRACE);
});

it('should not drop event with an exception that has a value', () => {
const eventProcessor = createInboundFiltersEventProcessor();
expect(eventProcessor(EVENT_WITH_VALUE, {})).toBe(EVENT_WITH_VALUE);
});
});
});
Loading