fix(core): Fix sentry de-duplication by migrating from event-processors to beforeSend (no-changelog) (#10947)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2024-09-24 16:53:18 +02:00 committed by GitHub
parent dcc1c72fc4
commit a81256aff5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -29,7 +29,7 @@ export const initErrorHandling = async () => {
DEPLOYMENT_NAME: serverName,
} = process.env;
const { init, captureException, addEventProcessor } = await import('@sentry/node');
const { init, captureException } = await import('@sentry/node');
const { RewriteFrames } = await import('@sentry/integrations');
const { Integrations } = await import('@sentry/node');
@ -41,6 +41,8 @@ export const initErrorHandling = async () => {
'OnUnhandledRejection',
'ContextLines',
];
const seenErrors = new Set<string>();
init({
dsn,
release,
@ -62,34 +64,32 @@ export const initErrorHandling = async () => {
},
}),
],
});
beforeSend(event, { originalException }) {
if (!originalException) return null;
const seenErrors = new Set<string>();
addEventProcessor((event, { originalException }) => {
if (!originalException) return null;
if (
originalException instanceof QueryFailedError &&
['SQLITE_FULL', 'SQLITE_IOERR'].some((errMsg) => originalException.message.includes(errMsg))
) {
return null;
}
if (
originalException instanceof QueryFailedError &&
['SQLITE_FULL', 'SQLITE_IOERR'].some((errMsg) => originalException.message.includes(errMsg))
) {
return null;
}
if (originalException instanceof ApplicationError) {
const { level, extra, tags } = originalException;
if (level === 'warning') return null;
event.level = level;
if (extra) event.extra = { ...event.extra, ...extra };
if (tags) event.tags = { ...event.tags, ...tags };
}
if (originalException instanceof ApplicationError) {
const { level, extra, tags } = originalException;
if (level === 'warning') return null;
event.level = level;
if (extra) event.extra = { ...event.extra, ...extra };
if (tags) event.tags = { ...event.tags, ...tags };
}
if (originalException instanceof Error && originalException.stack) {
const eventHash = createHash('sha1').update(originalException.stack).digest('base64');
if (seenErrors.has(eventHash)) return null;
seenErrors.add(eventHash);
}
if (originalException instanceof Error && originalException.stack) {
const eventHash = createHash('sha1').update(originalException.stack).digest('base64');
if (seenErrors.has(eventHash)) return null;
seenErrors.add(eventHash);
}
return event;
return event;
},
});
ErrorReporterProxy.init({