Compare commits

...

1 Commits

Author SHA1 Message Date
Hardik
2edb9c1bfb chore(sentry): exclude anonymous sentry errors 2026-11-16 08:52:11 +05:30
3 changed files with 30 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ import { AxiosError, AxiosHeaders } from 'axios';
import {
hasNoAppFrames,
isInjectedScriptError,
isExpectedRequestFailure,
isExternalIntegrationError,
SENTRY_IGNORE_ERRORS,
@@ -129,6 +130,24 @@ describe('hasNoAppFrames', () => {
});
});
describe('isInjectedScriptError', () => {
it('drops an error thrown from eval code behind the Sentry wrapper', () => {
expect(
isInjectedScriptError(eventWithFrames(APP_BUNDLE, '<anonymous>')),
).toBe(true);
});
it('keeps an error thrown from our bundle', () => {
expect(
isInjectedScriptError(eventWithFrames('<anonymous>', APP_BUNDLE)),
).toBe(false);
});
it('keeps an error without a stack trace', () => {
expect(isInjectedScriptError({ type: undefined })).toBe(false);
});
});
describe('SENTRY_IGNORE_ERRORS', () => {
it('ignores the bundled PostHog recorder load failure', () => {
expect(

View File

@@ -42,6 +42,7 @@ import {
hasNoAppFrames,
isExpectedRequestFailure,
isExternalIntegrationError,
isInjectedScriptError,
SENTRY_IGNORE_ERRORS,
} from './sentryFilters';
@@ -355,7 +356,7 @@ function App(): JSX.Element {
return null;
}
if (isExternalIntegrationError(event)) {
if (isExternalIntegrationError(event) || isInjectedScriptError(event)) {
return null;
}

View File

@@ -44,6 +44,15 @@ export function hasNoAppFrames(event: ErrorEvent): boolean {
);
}
// The throwing frame is the last one. Sentry's own timer wrapper is bundled
// with the app, so only the top frame shows the code came from an eval.
export function isInjectedScriptError(event: ErrorEvent): boolean {
return (event.exception?.values ?? []).some((exception) => {
const frames = exception.stacktrace?.frames ?? [];
return frames[frames.length - 1]?.filename === '<anonymous>';
});
}
// PostHog's lazy recorder, the Pylon widget and Appcues.
const EXTERNAL_SCRIPT_URLS = [
/^https?:\/\/[^/]+\.posthog\.com\//,