Skip to content

@sentry/node imports @opentelemetry/api and the wrong folder is traced #25

@ernestoalejo

Description

@ernestoalejo

Environment

node v22.14.0
nitro 3.0.1-alpha.2
└── nf3 0.3.10
vite 8.0.0-beta.15

Reproduction

https://github.com/ernestoalejo/reproduction-nf3-bug

It's an empty nitro v3 + vite beta project, with @sentry/node added to the traceDeps configuration.

Describe the bug

We trace @sentry/node to avoid issues because:
(1) It is included in the default list here: https://github.com/unjs/nf3/blob/main/src/db.ts#L137
(2) It uses an external instrument.js file not bundled inside the server code that inits the SDK. See: https://docs.sentry.io/platforms/javascript/guides/node/install/esm/

Ideally, we're aiming to run (instrument.js copied manually in that location):

node --import ./.output/server/instrument.js .output/server/index.mjs

When tracing @opentelemetry/api dependency of sentry ( https://github.com/open-telemetry/opentelemetry-js/blob/main/api/package.json#L10 ), nf3 prefers the module file copying the build/esm/... scripts, but Node resolves the default field that prefers build/src/... resulting in an error at runtime:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/opt/ac/.output/server/node_modules/@opentelemetry/api/build/src/index.js' imported from /opt/ac/.output/server/node_modules/@sentry/node/build/esm/integrations/http.js

I think it's related to this other nitro issue nitrojs/nitro#1988 and it seems similar too to the protobuf-es discussion some time ago. I don't know if it's an opentelemetry issue that can be solved with the order of fields in package.json; if we need the fullTraceInclude option currently in a PR to copy the full package without tracing/bundling it; or if there's another way of fixing this incompatibility of sentry with bundlers.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions