Compare commits

...

1 Commits

Author SHA1 Message Date
Ashwin Bhatkal
50504bb86b chore(sentry): drop errors with no frames from app code 2026-10-29 19:20:53 +05:30
3 changed files with 83 additions and 0 deletions

View File

@@ -30,6 +30,7 @@ import { useAppContext } from 'providers/App/App';
import { IUser } from 'providers/App/types';
import { LicenseStatus } from 'types/api/licensesV3/getActive';
import { extractDomain } from 'utils/app';
import { hasNoAppFrames } from 'utils/sentry';
import { Home } from './pageComponents';
import PrivateRoute from './Private';
@@ -366,6 +367,11 @@ function App(): JSX.Element {
return null;
}
// Dev serves source from /src/, so every frame would look foreign there.
if (process.env.NODE_ENV === 'production' && hasNoAppFrames(event)) {
return null;
}
const sessionReplayUrl = posthog.get_session_replay_url?.({
withTimestamp: true,
});

View File

@@ -0,0 +1,61 @@
import type { Event, StackFrame } from '@sentry/react';
import { hasNoAppFrames } from '../sentry';
const PAGE_URL = 'https://acme.signoz.cloud/dashboard/01a081e1';
const APP_CHUNK_URL = 'https://acme.signoz.cloud/assets/index-CcNiYOcv.js';
const errorEvent = (frames: StackFrame[]): Event => ({
exception: {
values: [{ type: 'SyntaxError', stacktrace: { frames } }],
},
});
describe('hasNoAppFrames', () => {
it('is true for a script injected into the page', () => {
expect(
hasNoAppFrames(
errorEvent([
{ filename: PAGE_URL, lineno: 1, colno: 30, function: 'global code' },
{ filename: '[native code]', function: 'eval' },
{ filename: '[native code]', function: 'append' },
]),
),
).toBe(true);
});
it('is true for a browser extension', () => {
expect(
hasNoAppFrames(
errorEvent([
{ filename: 'chrome-extension://abc/content.js', lineno: 4, colno: 12 },
]),
),
).toBe(true);
});
it('is false when any frame comes from an app chunk', () => {
expect(
hasNoAppFrames(
errorEvent([
{ filename: PAGE_URL, lineno: 1, colno: 30 },
{ filename: APP_CHUNK_URL, lineno: 2, colno: 4410 },
]),
),
).toBe(false);
});
it('is false for an event without an exception', () => {
expect(
hasNoAppFrames({ message: 'Received unknown severity on Alert Details' }),
).toBe(false);
});
it('is false when no frame has a position', () => {
expect(
hasNoAppFrames(
errorEvent([{ filename: '[native code]', function: 'eval' }]),
),
).toBe(false);
});
});

View File

@@ -0,0 +1,16 @@
import type { Event } from '@sentry/react';
const VITE_ASSETS_PATH = '/assets/';
export function hasNoAppFrames(event: Event): boolean {
const frames = (event.exception?.values ?? [])
.flatMap((value) => value.stacktrace?.frames ?? [])
.filter(
(frame) => frame.filename && (frame.lineno != null || frame.colno != null),
);
return (
frames.length > 0 &&
!frames.some((frame) => frame.filename?.includes(VITE_ASSETS_PATH))
);
}