Description
Package + Version
-
@sentry/node
: 6.13.3 -
@sentry/tracing
: 6.13.3
Version:
6.13.3
Description
While trying to add tracing instrumentation for mongoose
in a nodejs app that uses Yarn 3.0 in PnP mode I noticed that nothing was happening, and tracing was silently failing to do anything.
The problem is that PnP mode is strict about which dependencies are allowed to be required, and a package that doesn't define the dep in its package.json (dependencies or peerDependencies) will not be able to require it.
Neither @sentry/tracing
or @sentry/utils
list mongoose
/mongodb
/pg
/mysql
as dependencies.
The reason this fails is:
sentry-javascript/packages/tracing/src/integrations/node/mongo.ts
Lines 122 to 123 in 84a6dc0
Which then delegates to:
sentry-javascript/packages/utils/src/node.ts
Lines 42 to 46 in 84a6dc0
That empty catch actually suppresses this error:
Error: @sentry/utils tried to access mongoose (a peer dependency) but it isn't provided by its ancestors; this makes the require call ambiguous and unsound.
Required package: mongoose
Required by: @sentry/utils@virtual:...
Ancestor breaking the chain: @sentry/core@npm:6.13.3
Ancestor breaking the chain: @sentry/hub@npm:6.13.3
Ancestor breaking the chain: @sentry/node@npm:6.13.3
This is going to be tricky to fix because of the long chain of dependencies needing to pass the target dependency along properly.
One possible suggestion to get around this would be to:
- make the error clearer to the user
- make it possible to inject the library via the constructor in:
sentry-javascript/packages/tracing/src/integrations/node/mongo.ts
Lines 85 to 89 in 84a6dc0
The caller might then do something like:
const MongoTracingIntegration = new Tracing.Integrations.Mongo({
collection: require("mongoose").Collection,
});
This would bypass the require
call being done by the sentry library, and delegate it to the user instead, providing a way around the problem.
Something similar would need to be done with all the other integrations.
Slightly related: #3172 (different issue on PnP)