refactor(core): Update backend sentry setup to reduce noise (no-changelog) (#8026)
## Summary This PR updates our backend sentry setup to remove integrations that don't provide us any value. This also reduces the amount of PII that gets sent to Sentry. [Sample event](https://n8nio.sentry.io/issues/4725315362/) ## Related tickets [ENG-95](https://linear.app/n8n/issue/ENG-95) ## Review / Merge checklist - [x] PR title and summary are descriptive.
This commit is contained in:
committed by
GitHub
parent
614f488386
commit
a651089a10
@@ -12,7 +12,7 @@ export const initErrorHandling = async () => {
|
||||
});
|
||||
|
||||
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
|
||||
if (!config.getEnv('diagnostics.enabled') || !dsn) {
|
||||
if (!dsn) {
|
||||
initialized = true;
|
||||
return;
|
||||
}
|
||||
@@ -20,25 +20,51 @@ export const initErrorHandling = async () => {
|
||||
// Collect longer stacktraces
|
||||
Error.stackTraceLimit = 50;
|
||||
|
||||
const { N8N_VERSION: release, ENVIRONMENT: environment } = process.env;
|
||||
const {
|
||||
N8N_VERSION: release,
|
||||
ENVIRONMENT: environment,
|
||||
DEPLOYMENT_NAME: serverName,
|
||||
} = process.env;
|
||||
|
||||
const { init, captureException, addGlobalEventProcessor } = await import('@sentry/node');
|
||||
const { init, captureException, addEventProcessor } = await import('@sentry/node');
|
||||
|
||||
const { RewriteFrames } = await import('@sentry/integrations');
|
||||
const { Integrations } = await import('@sentry/node');
|
||||
|
||||
const enabledIntegrations = [
|
||||
'InboundFilters',
|
||||
'FunctionToString',
|
||||
'LinkedErrors',
|
||||
'OnUnhandledRejection',
|
||||
'ContextLines',
|
||||
];
|
||||
init({
|
||||
dsn,
|
||||
release,
|
||||
environment,
|
||||
integrations: (integrations) => {
|
||||
integrations = integrations.filter(({ name }) => name !== 'OnUncaughtException');
|
||||
integrations.push(new RewriteFrames({ root: process.cwd() }));
|
||||
return integrations;
|
||||
},
|
||||
enableTracing: false,
|
||||
serverName,
|
||||
beforeBreadcrumb: () => null,
|
||||
integrations: (integrations) => [
|
||||
...integrations.filter(({ name }) => enabledIntegrations.includes(name)),
|
||||
new RewriteFrames({ root: process.cwd() }),
|
||||
new Integrations.RequestData({
|
||||
include: {
|
||||
cookies: false,
|
||||
data: false,
|
||||
headers: false,
|
||||
query_string: false,
|
||||
url: true,
|
||||
user: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
const seenErrors = new Set<string>();
|
||||
addGlobalEventProcessor((event, { originalException }) => {
|
||||
addEventProcessor((event, { originalException }) => {
|
||||
if (!originalException) return null;
|
||||
|
||||
if (originalException instanceof ApplicationError) {
|
||||
const { level, extra, tags } = originalException;
|
||||
if (level === 'warning') return null;
|
||||
@@ -47,8 +73,7 @@ export const initErrorHandling = async () => {
|
||||
if (tags) event.tags = { ...event.tags, ...tags };
|
||||
}
|
||||
|
||||
if (!event.exception) return null;
|
||||
const eventHash = createHash('sha1').update(JSON.stringify(event.exception)).digest('base64');
|
||||
const eventHash = createHash('sha1').update(JSON.stringify(originalException)).digest('base64');
|
||||
if (seenErrors.has(eventHash)) return null;
|
||||
seenErrors.add(eventHash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user