feat(core): Reduce the number of events sent to Sentry (#6235)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-05-15 13:54:48 +00:00
committed by GitHub
parent 9182d1558a
commit a4c0cc9b5c
5 changed files with 49 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { createHash } from 'crypto';
import config from '@/config';
import { ErrorReporterProxy } from 'n8n-workflow';
import { ErrorReporterProxy, NodeError } from 'n8n-workflow';
let initialized = false;
@@ -17,7 +18,7 @@ export const initErrorHandling = async () => {
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
const { N8N_VERSION: release, ENVIRONMENT: environment } = process.env;
const { init, captureException } = await import('@sentry/node');
const { init, captureException, addGlobalEventProcessor } = await import('@sentry/node');
// eslint-disable-next-line @typescript-eslint/naming-convention
const { RewriteFrames } = await import('@sentry/integrations');
@@ -32,6 +33,17 @@ export const initErrorHandling = async () => {
},
});
const seenErrors = new Set<string>();
addGlobalEventProcessor((event, { originalException }) => {
if (originalException instanceof NodeError && originalException.severity === 'warning')
return null;
if (!event.exception) return null;
const eventHash = createHash('sha1').update(JSON.stringify(event.exception)).digest('base64');
if (seenErrors.has(eventHash)) return null;
seenErrors.add(eventHash);
return event;
});
process.on('uncaughtException', (error) => {
ErrorReporterProxy.error(error);
if (error.constructor?.name !== 'AxiosError') throw error;