From a81256aff5e70b57cd47e871c3389f749577e6d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Tue, 24 Sep 2024 16:53:18 +0200 Subject: [PATCH] fix(core): Fix sentry de-duplication by migrating from event-processors to beforeSend (no-changelog) (#10947) --- packages/cli/src/error-reporting.ts | 50 ++++++++++++++--------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/cli/src/error-reporting.ts b/packages/cli/src/error-reporting.ts index 64a7696a77..5628615faa 100644 --- a/packages/cli/src/error-reporting.ts +++ b/packages/cli/src/error-reporting.ts @@ -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(); + init({ dsn, release, @@ -62,34 +64,32 @@ export const initErrorHandling = async () => { }, }), ], - }); + beforeSend(event, { originalException }) { + if (!originalException) return null; - const seenErrors = new Set(); - 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({