Skip to content

Missing @opentelemetry/instrumentation dependency during nextjs build #20185

@rchl-u

Description

@rchl-u

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

10.47.0

Framework Version

Next 16.2.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Install @sentry/nextjs in a monorepo project where multiple packages use @sentry/nextjs.
  2. Build Next

Expected Result

Required dependencies being present.

Actual Result

> Build error occurred
Error: Cannot find module '@opentelemetry/instrumentation'
Require stack:
- /project/node_modules/@sentry/node-core/build/cjs/otel/instrument.js
- /project/node_modules/@sentry/node-core/build/cjs/integrations/http/index.js
- /project/node_modules/@sentry/node-core/build/cjs/index.js
- /project/node_modules/@sentry/node/build/cjs/integrations/http.js
- /project/node_modules/@sentry/node/build/cjs/index.js
- /project/node_modules/@sentry/nextjs/build/cjs/config/withSentryConfig/getFinalConfigObjectUtils.js
- /project/node_modules/@sentry/nextjs/build/cjs/config/withSentryConfig/getFinalConfigObject.js
- /project/node_modules/@sentry/nextjs/build/cjs/config/withSentryConfig/index.js
- /project/node_modules/@sentry/nextjs/build/cjs/index.server.js
- /project/apps/app-name/next.config.compiled.js
- /project/node_modules/next/dist/build/next-config-ts/transpile-config.js
- /project/node_modules/next/dist/server/config.js
- /project/node_modules/next/dist/cli/next-test.js
- /project/node_modules/next/dist/bin/next

Additional Context

I did not make reproduction for this because it would take too much time to figure out how to reproduce it with minimal project but I think the require stack shows that there is problem with dependency setup in sentry packages.

It obviously involves a monorepo with additional packages that also use @sentry/nextjs or even @opentelemetry to trigger npm into certain dependency layout when it comes to ``@opentelemetry/*` dependencies.

Why I think it's a problem with sentry packages is because @sentry/node-core explicitly imports @opentelemetry/instrumentation but doesn't have it in its dependencies.

Yes, It does specify it in peerDependencies but that doesn't really do anything automatically (not with npm at least). It's just an indication that the user of this package should install those dependencies. But there is no indication anywhere in the documentation that those packages should be explicitly installed.

I see how having those as explicit dependencies might not be ideal since it's a shared core package and not every user of it should need those but it's npm and I think a choice has to be made - correct dependency tree and corresponding bloat or random errors like that.

Priority

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions