diff --git a/packages/node/src/integrations/manualExpressInstrumentation.ts b/packages/node/src/integrations/manualExpressInstrumentation.ts new file mode 100644 index 000000000000..ebe9fcbc8f85 --- /dev/null +++ b/packages/node/src/integrations/manualExpressInstrumentation.ts @@ -0,0 +1,16 @@ +import * as Sentry from '@sentry/node'; + +export function instrumentExpressManually(): void { + try { + const express = require('express'); + const { instrument } = require('@sentry/integrations/build/cjs/express'); + if (express && !express.__sentry_instrumented__) { + instrument(express); + express.__sentry_instrumented__ = true; + } + } catch (e) { + if (process.env.NODE_ENV !== 'production') { + console.warn('Failed to manually instrument Express:', e); + } + } +} \ No newline at end of file