mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(core): Reduce the number of events sent to Sentry (#6235)
This commit is contained in:
parent
9182d1558a
commit
a4c0cc9b5c
|
@ -1,5 +1,6 @@
|
||||||
|
import { createHash } from 'crypto';
|
||||||
import config from '@/config';
|
import config from '@/config';
|
||||||
import { ErrorReporterProxy } from 'n8n-workflow';
|
import { ErrorReporterProxy, NodeError } from 'n8n-workflow';
|
||||||
|
|
||||||
let initialized = false;
|
let initialized = false;
|
||||||
|
|
||||||
|
@ -17,7 +18,7 @@ export const initErrorHandling = async () => {
|
||||||
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
|
const dsn = config.getEnv('diagnostics.config.sentry.dsn');
|
||||||
const { N8N_VERSION: release, ENVIRONMENT: environment } = process.env;
|
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
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
const { RewriteFrames } = await import('@sentry/integrations');
|
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) => {
|
process.on('uncaughtException', (error) => {
|
||||||
ErrorReporterProxy.error(error);
|
ErrorReporterProxy.error(error);
|
||||||
if (error.constructor?.name !== 'AxiosError') throw error;
|
if (error.constructor?.name !== 'AxiosError') throw error;
|
||||||
|
|
|
@ -71,6 +71,7 @@ export class PermissionChecker {
|
||||||
|
|
||||||
throw new NodeOperationError(nodeToFlag, 'Node has no access to credential', {
|
throw new NodeOperationError(nodeToFlag, 'Node has no access to credential', {
|
||||||
description: 'Please recreate the credential or ask its owner to share it with you.',
|
description: 'Please recreate the credential or ask its owner to share it with you.',
|
||||||
|
severity: 'warning',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1392,6 +1392,7 @@ export async function httpRequestWithAuthentication(
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
node,
|
node,
|
||||||
`Node "${node.name}" does not have any credentials of type "${credentialsType}" set!`,
|
`Node "${node.name}" does not have any credentials of type "${credentialsType}" set!`,
|
||||||
|
{ severity: 'warning' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1587,6 +1588,7 @@ export async function requestWithAuthentication(
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
node,
|
node,
|
||||||
`Node "${node.name}" does not have any credentials of type "${credentialsType}" set!`,
|
`Node "${node.name}" does not have any credentials of type "${credentialsType}" set!`,
|
||||||
|
{ severity: 'warning' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1745,6 +1747,7 @@ export async function getCredentials(
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
node,
|
node,
|
||||||
`Node type "${node.type}" does not have any credentials defined!`,
|
`Node type "${node.type}" does not have any credentials defined!`,
|
||||||
|
{ severity: 'warning' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1755,6 +1758,7 @@ export async function getCredentials(
|
||||||
throw new NodeOperationError(
|
throw new NodeOperationError(
|
||||||
node,
|
node,
|
||||||
`Node type "${node.type}" does not have any credentials of type "${type}" defined!`,
|
`Node type "${node.type}" does not have any credentials of type "${type}" defined!`,
|
||||||
|
{ severity: 'warning' },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1778,10 +1782,16 @@ export async function getCredentials(
|
||||||
if (nodeCredentialDescription?.required === true) {
|
if (nodeCredentialDescription?.required === true) {
|
||||||
// Credentials are required so error
|
// Credentials are required so error
|
||||||
if (!node.credentials) {
|
if (!node.credentials) {
|
||||||
throw new NodeOperationError(node, 'Node does not have any credentials set!');
|
throw new NodeOperationError(node, 'Node does not have any credentials set!', {
|
||||||
|
severity: 'warning',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (!node.credentials[type]) {
|
if (!node.credentials[type]) {
|
||||||
throw new NodeOperationError(node, `Node does not have any credentials set for "${type}"!`);
|
throw new NodeOperationError(
|
||||||
|
node,
|
||||||
|
`Node does not have any credentials set for "${type}"!`,
|
||||||
|
{ severity: 'warning' },
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Credentials are not required
|
// Credentials are not required
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
import { parseString } from 'xml2js';
|
import { parseString } from 'xml2js';
|
||||||
import type { IDataObject, INode, IStatusCodeMessages, JsonObject } from './Interfaces';
|
import type { IDataObject, INode, IStatusCodeMessages, JsonObject } from './Interfaces';
|
||||||
|
|
||||||
|
type Severity = 'warning' | 'error';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Top-level properties where an error message can be found in an API response.
|
* Top-level properties where an error message can be found in an API response.
|
||||||
*/
|
*/
|
||||||
|
@ -103,9 +105,11 @@ export abstract class ExecutionBaseError extends Error {
|
||||||
* Base class for specific NodeError-types, with functionality for finding
|
* Base class for specific NodeError-types, with functionality for finding
|
||||||
* a value recursively inside an error object.
|
* a value recursively inside an error object.
|
||||||
*/
|
*/
|
||||||
abstract class NodeError extends ExecutionBaseError {
|
export abstract class NodeError extends ExecutionBaseError {
|
||||||
node: INode;
|
node: INode;
|
||||||
|
|
||||||
|
severity: Severity = 'error';
|
||||||
|
|
||||||
constructor(node: INode, error: Error | JsonObject) {
|
constructor(node: INode, error: Error | JsonObject) {
|
||||||
const message = error instanceof Error ? error.message : '';
|
const message = error instanceof Error ? error.message : '';
|
||||||
super(message, { cause: error });
|
super(message, { cause: error });
|
||||||
|
@ -234,6 +238,7 @@ interface NodeOperationErrorOptions {
|
||||||
description?: string;
|
description?: string;
|
||||||
runIndex?: number;
|
runIndex?: number;
|
||||||
itemIndex?: number;
|
itemIndex?: number;
|
||||||
|
severity?: Severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,9 +253,8 @@ export class NodeOperationError extends NodeError {
|
||||||
}
|
}
|
||||||
super(node, error);
|
super(node, error);
|
||||||
|
|
||||||
if (options.message) {
|
if (options.message) this.message = options.message;
|
||||||
this.message = options.message;
|
if (options.severity) this.severity = options.severity;
|
||||||
}
|
|
||||||
this.description = options.description;
|
this.description = options.description;
|
||||||
this.context.runIndex = options.runIndex;
|
this.context.runIndex = options.runIndex;
|
||||||
this.context.itemIndex = options.itemIndex;
|
this.context.itemIndex = options.itemIndex;
|
||||||
|
@ -296,10 +300,21 @@ export class NodeApiError extends NodeError {
|
||||||
constructor(
|
constructor(
|
||||||
node: INode,
|
node: INode,
|
||||||
error: JsonObject,
|
error: JsonObject,
|
||||||
{ message, description, httpCode, parseXml, runIndex, itemIndex }: NodeApiErrorOptions = {},
|
{
|
||||||
|
message,
|
||||||
|
description,
|
||||||
|
httpCode,
|
||||||
|
parseXml,
|
||||||
|
runIndex,
|
||||||
|
itemIndex,
|
||||||
|
severity,
|
||||||
|
}: NodeApiErrorOptions = {},
|
||||||
) {
|
) {
|
||||||
super(node, error);
|
super(node, error);
|
||||||
|
|
||||||
|
if (severity) this.severity = severity;
|
||||||
|
else if (httpCode?.charAt(0) !== '5') this.severity = 'warning';
|
||||||
|
|
||||||
if (error.error) {
|
if (error.error) {
|
||||||
// only for request library error
|
// only for request library error
|
||||||
this.removeCircularRefs(error.error as JsonObject);
|
this.removeCircularRefs(error.error as JsonObject);
|
||||||
|
|
|
@ -217,11 +217,13 @@ export class RoutingNode {
|
||||||
returnData.push({ json: {}, error: error.message });
|
returnData.push({ json: {}, error: error.message });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (error instanceof NodeApiError) error = error.cause;
|
||||||
throw new NodeApiError(this.node, error, {
|
throw new NodeApiError(this.node, error, {
|
||||||
runIndex,
|
runIndex,
|
||||||
itemIndex: i,
|
itemIndex: i,
|
||||||
message: error?.message,
|
message: error?.message,
|
||||||
description: error?.description,
|
description: error?.description,
|
||||||
|
httpCode: error.isAxiosError && error.response && String(error.response?.status),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue