Open P4sca1 opened 1 month ago
Hey,
can you try to exclude this package from instrumentation - I just noticed this was not properly documented yet, so I added docs here https://github.com/getsentry/sentry-docs/pull/10803
So something like this:
Sentry.init({
registerEsmLoaderHooks: {
// Provide a list of package names to exclude from instrumentation
exclude: ["@simplewebauthn/server"],
},
});
You might need to use a regular expression:
Sentry.init({
registerEsmLoaderHooks: {
// Provide a list of package names to exclude from instrumentation
exclude: [/@simplewebauthn\/server/],
},
});
For regular expressions to work you'll need to ensure that v1.10.0
of import-in-the-middle
is in your dependencies. I only released this a few moments ago so you will need to remove your lock file and re-install or run npm/yarn update import-in-the-middle
to update to it.
The Sentry type definitions don't yet allow regular expressions so I've opened a PR for that.
Thank you for your help. After upgrading import-in-the-middle
to v1.10.0
and adding the following to my Sentry.init
options, I can confirm that using @simplewebauthn/server
is now working.
registerEsmLoaderHooks: {
// @ts-expect-error -- https://github.com/getsentry/sentry-javascript/pull/13016
exclude: [/@simplewebauthn\/server/],
},
It was indeed required to use regular expressions. Using "@simplewebauthn/server"
did not work.
Thank you for confirming!
We should hopefully have an update coming soon which will negate the need for this manual configuration.
v8.29.0 of the Node SDK adds the new onlyIncludeInstrumentedModules
option to registerEsmLoaderHooks
.
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: '__PUBLIC_DSN__',
registerEsmLoaderHooks: { onlyIncludeInstrumentedModules: true },
});
When set to true
, import-in-the-middle
will only wrap ESM modules that are specifically instrumented by OpenTelemetry plugins. This is useful to avoid issues where import-in-the-middle
is not compatible with some of your dependencies.
This feature will only work if you Sentry.init()
the SDK before the instrumented modules are loaded. This can be achieved via the Node --register
and --import
CLI flags or by loading your app code via async import()
after calling Sentry.init()
.
Please let me know if this helps solve the import-in-the-middle
incompatibility issues you are experiencing!
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
8.19.0
Framework Version
No response
Link to Sentry event
No response
SDK Setup/Reproduction Example
Steps to Reproduce
Install
@simplewebauthn/server
version 10.0.0.Expected Result
Using
@simplewebauthn/server
using Sentry intstrumentation in an ESM environment should work. Everything works fine when removing the--import ./instrument.js
flag.Actual Result