Skip to content

GitAuto: [Sentry] Express is not instrumented. This is likely because you required/imported express before calling Sentry.init() #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/node/src/integrations/manualExpressInstrumentation.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
}