Using Sentry v8 without HTTP autoinstrumentation #12982
Replies: 1 comment 2 replies
-
Unfortunately this is how Node.js has designed ESM to work - you have to use loaders to do auto-instrumentation (where we automatically wrap things). I understand it's not the best experience, we're trying to make changes in Node.js itself to make this better! Three things to note from your snippet:
OTEL implementation: https://github.com/open-telemetry/opentelemetry-js-contrib/blob/afccd0d62a0ea81afb8f5609f3ee802c038d11c6/plugins/node/opentelemetry-instrumentation-express/src/utils.ts#L153-L159 Old Sentry implementation:
|
Beta Was this translation helpful? Give feedback.
-
Sentry v8 removed the very convenient
Sentry.Handlers.requestHandler()
that could be dropped easily into an Express application. Now, instrumentation is "automagical" and requires one to jump through some hoops to get it to work, particularly if you're running native ESM. In my case, it would require a pretty invasive restructuring of my application's bootstrapping process to ensure that Sentry could put its hooks into everything when it wants to. If, like me, you don't care about Sentry's performance/transaction features and just want it to reliably capture errors and their associated context, I've found that this little snippet will more or less give you a Sentry v7 experience in Express applications:This can then be used as Express middleware:
I hopes this helps anyone else that's in a similar boat!
Beta Was this translation helpful? Give feedback.
All reactions