mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 16:44:07 -08:00
convert error reporting to a DI service
This commit is contained in:
parent
e7a4b0da01
commit
d9ecab0672
|
@ -21,7 +21,7 @@ import { LICENSE_FEATURES, inDevelopment, inTest } from '@/constants';
|
|||
import * as CrashJournal from '@/crash-journal';
|
||||
import * as Db from '@/db';
|
||||
import { getDataDeduplicationService } from '@/deduplication';
|
||||
import { initErrorHandling } from '@/error-reporting';
|
||||
import { ErrorReporting } from '@/error-reporting';
|
||||
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
|
||||
import { TelemetryEventRelay } from '@/events/relays/telemetry.event-relay';
|
||||
import { initExpressionEvaluator } from '@/expression-evaluator';
|
||||
|
@ -61,7 +61,7 @@ export abstract class BaseCommand extends Command {
|
|||
protected needsCommunityPackages = false;
|
||||
|
||||
async init(): Promise<void> {
|
||||
await initErrorHandling();
|
||||
await Container.get(ErrorReporting).init();
|
||||
initExpressionEvaluator();
|
||||
|
||||
process.once('SIGTERM', this.onTerminationSignal('SIGTERM'));
|
||||
|
|
|
@ -5,20 +5,27 @@ import { AxiosError } from 'axios';
|
|||
import { createHash } from 'crypto';
|
||||
import { InstanceSettings } from 'n8n-core';
|
||||
import { ErrorReporterProxy, ApplicationError } from 'n8n-workflow';
|
||||
import Container from 'typedi';
|
||||
import { Service } from 'typedi';
|
||||
|
||||
let initialized = false;
|
||||
@Service()
|
||||
export class ErrorReporting {
|
||||
private initialized = false;
|
||||
|
||||
export const initErrorHandling = async () => {
|
||||
if (initialized) return;
|
||||
constructor(
|
||||
private readonly globalConfig: GlobalConfig,
|
||||
private readonly instanceSettings: InstanceSettings,
|
||||
) {}
|
||||
|
||||
async init() {
|
||||
if (this.initialized) return;
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
ErrorReporterProxy.error(error);
|
||||
});
|
||||
|
||||
const dsn = Container.get(GlobalConfig).sentry.backendDsn;
|
||||
const dsn = this.globalConfig.sentry.backendDsn;
|
||||
if (!dsn) {
|
||||
initialized = true;
|
||||
this.initialized = true;
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +39,6 @@ export const initErrorHandling = async () => {
|
|||
} = process.env;
|
||||
|
||||
const { init, captureException, setTag } = await import('@sentry/node');
|
||||
|
||||
const { RewriteFrames } = await import('@sentry/integrations');
|
||||
const { Integrations } = await import('@sentry/node');
|
||||
|
||||
|
@ -73,7 +79,9 @@ export const initErrorHandling = async () => {
|
|||
|
||||
if (
|
||||
originalException instanceof QueryFailedError &&
|
||||
['SQLITE_FULL', 'SQLITE_IOERR'].some((errMsg) => originalException.message.includes(errMsg))
|
||||
['SQLITE_FULL', 'SQLITE_IOERR'].some((errMsg) =>
|
||||
originalException.message.includes(errMsg),
|
||||
)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
@ -96,11 +104,12 @@ export const initErrorHandling = async () => {
|
|||
},
|
||||
});
|
||||
|
||||
setTag('server_type', Container.get(InstanceSettings).instanceType);
|
||||
setTag('server_type', this.instanceSettings.instanceType);
|
||||
|
||||
ErrorReporterProxy.init({
|
||||
report: (error, options) => captureException(error, options),
|
||||
});
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
this.initialized = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue