mirror of
https://github.com/n8n-io/n8n.git
synced 2025-01-11 21:07:28 -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 { 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;
|
||||
|
|
|
@ -71,6 +71,7 @@ export class PermissionChecker {
|
|||
|
||||
throw new NodeOperationError(nodeToFlag, 'Node has no access to credential', {
|
||||
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(
|
||||
node,
|
||||
`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(
|
||||
node,
|
||||
`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(
|
||||
node,
|
||||
`Node type "${node.type}" does not have any credentials defined!`,
|
||||
{ severity: 'warning' },
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1755,6 +1758,7 @@ export async function getCredentials(
|
|||
throw new NodeOperationError(
|
||||
node,
|
||||
`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) {
|
||||
// Credentials are required so error
|
||||
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]) {
|
||||
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 {
|
||||
// Credentials are not required
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
import { parseString } from 'xml2js';
|
||||
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.
|
||||
*/
|
||||
|
@ -103,9 +105,11 @@ export abstract class ExecutionBaseError extends Error {
|
|||
* Base class for specific NodeError-types, with functionality for finding
|
||||
* a value recursively inside an error object.
|
||||
*/
|
||||
abstract class NodeError extends ExecutionBaseError {
|
||||
export abstract class NodeError extends ExecutionBaseError {
|
||||
node: INode;
|
||||
|
||||
severity: Severity = 'error';
|
||||
|
||||
constructor(node: INode, error: Error | JsonObject) {
|
||||
const message = error instanceof Error ? error.message : '';
|
||||
super(message, { cause: error });
|
||||
|
@ -234,6 +238,7 @@ interface NodeOperationErrorOptions {
|
|||
description?: string;
|
||||
runIndex?: number;
|
||||
itemIndex?: number;
|
||||
severity?: Severity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,9 +253,8 @@ export class NodeOperationError extends NodeError {
|
|||
}
|
||||
super(node, error);
|
||||
|
||||
if (options.message) {
|
||||
this.message = options.message;
|
||||
}
|
||||
if (options.message) this.message = options.message;
|
||||
if (options.severity) this.severity = options.severity;
|
||||
this.description = options.description;
|
||||
this.context.runIndex = options.runIndex;
|
||||
this.context.itemIndex = options.itemIndex;
|
||||
|
@ -296,10 +300,21 @@ export class NodeApiError extends NodeError {
|
|||
constructor(
|
||||
node: INode,
|
||||
error: JsonObject,
|
||||
{ message, description, httpCode, parseXml, runIndex, itemIndex }: NodeApiErrorOptions = {},
|
||||
{
|
||||
message,
|
||||
description,
|
||||
httpCode,
|
||||
parseXml,
|
||||
runIndex,
|
||||
itemIndex,
|
||||
severity,
|
||||
}: NodeApiErrorOptions = {},
|
||||
) {
|
||||
super(node, error);
|
||||
|
||||
if (severity) this.severity = severity;
|
||||
else if (httpCode?.charAt(0) !== '5') this.severity = 'warning';
|
||||
|
||||
if (error.error) {
|
||||
// only for request library error
|
||||
this.removeCircularRefs(error.error as JsonObject);
|
||||
|
|
|
@ -217,11 +217,13 @@ export class RoutingNode {
|
|||
returnData.push({ json: {}, error: error.message });
|
||||
continue;
|
||||
}
|
||||
if (error instanceof NodeApiError) error = error.cause;
|
||||
throw new NodeApiError(this.node, error, {
|
||||
runIndex,
|
||||
itemIndex: i,
|
||||
message: error?.message,
|
||||
description: error?.description,
|
||||
httpCode: error.isAxiosError && error.response && String(error.response?.status),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue