fix(core): Dynamically import @sentry/node-native (#18586)

This commit is contained in:
Iván Ovejero
2025-08-20 11:31:00 +02:00
committed by GitHub
parent fb3a2ae216
commit 0f463c781d

View File

@@ -4,7 +4,6 @@ import { Service } from '@n8n/di';
import type { ReportingOptions } from '@n8n/errors';
import type { ErrorEvent, EventHint } from '@sentry/core';
import type { NodeOptions } from '@sentry/node';
import { eventLoopBlockIntegration } from '@sentry/node-native';
import { AxiosError } from 'axios';
import { ApplicationError, ExecutionCancelledError, BaseError } from 'n8n-workflow';
import { createHash } from 'node:crypto';
@@ -127,6 +126,8 @@ export class ErrorReporter {
'ContextLines',
];
const eventLoopBlockIntegration = await this.getEventLoopBlockIntegration();
init({
dsn,
release,
@@ -147,7 +148,7 @@ export class ErrorReporter {
url: true,
},
}),
eventLoopBlockIntegration(),
...eventLoopBlockIntegration,
],
});
@@ -253,4 +254,16 @@ export class ErrorReporter {
if (extra) event.extra = { ...event.extra, ...extra };
if (tags) event.tags = { ...event.tags, ...tags };
}
private async getEventLoopBlockIntegration() {
try {
const { eventLoopBlockIntegration } = await import('@sentry/node-native');
return [eventLoopBlockIntegration()];
} catch {
this.logger.debug(
"Sentry's event loop block integration is disabled, because the native binary for `@sentry/node-native` was not found",
);
return [];
}
}
}