mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
Keep reporting [path-related errors](https://n8nio.sentry.io/issues/4649493725) in Sentry but consolidate them in a single error group. Also, add `options.extra` as `meta` so they remain visible in debug logs: ``` 2023-11-24T11:50:54.852Z | error | ReportableError: Something went wrong "{ test: 123, file: 'LoggerProxy.js', function: 'exports.error' }" ``` --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import { createHash } from 'crypto';
|
|
import config from '@/config';
|
|
import { ErrorReporterProxy, ExecutionBaseError, ReportableError } from 'n8n-workflow';
|
|
|
|
let initialized = false;
|
|
|
|
export const initErrorHandling = async () => {
|
|
if (initialized) return;
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
ErrorReporterProxy.error(error);
|
|
});
|
|
|
|
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
|
|
if (!config.getEnv('diagnostics.enabled') || !dsn) {
|
|
initialized = true;
|
|
return;
|
|
}
|
|
|
|
// Collect longer stacktraces
|
|
Error.stackTraceLimit = 50;
|
|
|
|
const { N8N_VERSION: release, ENVIRONMENT: environment } = process.env;
|
|
|
|
const { init, captureException, addGlobalEventProcessor } = await import('@sentry/node');
|
|
|
|
const { RewriteFrames } = await import('@sentry/integrations');
|
|
|
|
init({
|
|
dsn,
|
|
release,
|
|
environment,
|
|
integrations: (integrations) => {
|
|
integrations = integrations.filter(({ name }) => name !== 'OnUncaughtException');
|
|
integrations.push(new RewriteFrames({ root: process.cwd() }));
|
|
return integrations;
|
|
},
|
|
});
|
|
|
|
const seenErrors = new Set<string>();
|
|
addGlobalEventProcessor((event, { originalException }) => {
|
|
if (originalException instanceof ExecutionBaseError && originalException.severity === 'warning')
|
|
return null;
|
|
|
|
if (originalException instanceof ReportableError) {
|
|
const { level, extra } = originalException;
|
|
if (level === 'warning') return null;
|
|
event.level = level;
|
|
if (extra) event.extra = { ...event.extra, ...extra };
|
|
}
|
|
|
|
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;
|
|
});
|
|
|
|
ErrorReporterProxy.init({
|
|
report: (error, options) => captureException(error, options),
|
|
});
|
|
|
|
initialized = true;
|
|
};
|