diff --git a/packages/instrumentation-sentry-node/src/instrumentation.ts b/packages/instrumentation-sentry-node/src/instrumentation.ts index 702d39ba..46a9173d 100644 --- a/packages/instrumentation-sentry-node/src/instrumentation.ts +++ b/packages/instrumentation-sentry-node/src/instrumentation.ts @@ -35,12 +35,18 @@ export class SentryNodeInstrumentation extends InstrumentationBase { this._wrap(moduleExports, 'init', (original: any) => { return (...args: any[]) => { const result = original.apply(this, args); - if (moduleExports.addIntegration instanceof Function) { - // WARNING: we need to add the integration once the SDK is initialized - moduleExports.addIntegration(hyperdxIntegration()); - diag.debug('Added HyperDX Sentry integration.'); - } else { - diag.error('Could not add HyperDX Sentry integration'); + try { + if (moduleExports.addIntegration instanceof Function) { + // WARNING: we need to add the integration once the SDK is initialized + moduleExports.addIntegration(hyperdxIntegration()); + diag.debug('Added HyperDX Sentry integration'); + } else { + diag.error( + 'Sentry SDK does not support addIntegration method', + ); + } + } catch (e) { + diag.error('Error adding HyperDX Sentry integration', e); } return result; };