Skip to content

Comments

fix (docs): Laminar observability - add note on next.config#6248

Merged
nicoalbanese merged 2 commits intovercel:mainfrom
lmnr-ai:docs/laminar
May 13, 2025
Merged

fix (docs): Laminar observability - add note on next.config#6248
nicoalbanese merged 2 commits intovercel:mainfrom
lmnr-ai:docs/laminar

Conversation

@dinmukhamedm
Copy link
Contributor

@dinmukhamedm dinmukhamedm commented May 9, 2025

Background

Like many other OpenTelemetry instrumentations, Laminar depends on @opentelemetry/instrumentation, which, in turn, depends on require-in-the-middle and import-in-the-middle. Importing and initializing Laminar inside Next.js instrumentation.ts file causes Next.js to try resolving these two packages, but fails, and results in:

  • Laminar not being able to send traces. This is because unlike many other instrumentation libraries, Laminar is not intrusive and does not set its tracer provider globally (so that others, e.g. @vercel/otel can set theirs).
  • Error messages (see below)

We have tried many different things to debug, including bundling Laminar differently, shipping those two packages within Laminar as noExternal, adding a separate entrypoint in our package for Next.js, but nothing seems to have worked.

The only thing that's worked was adding @lmnr-ai/lmnr in serverExternalPackages in next.config.

Example error message without turbopack:

 ⚠ ./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
Critical dependency: the request of a dependency is an expression

Import trace for requested module:
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/index.js
./node_modules/.pnpm/@lmnr-ai+lmnr@file+..+..+ts-sdk/node_modules/@lmnr-ai/lmnr/dist/index.js

./node_modules/.pnpm/require-in-the-middle@7.5.2/node_modules/require-in-the-middle/index.js
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Import trace for requested module:
./node_modules/.pnpm/require-in-the-middle@7.5.2/node_modules/require-in-the-middle/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/index.js
./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/index.js
./node_modules/.pnpm/@lmnr-ai+lmnr@file+..+..+ts-sdk/node_modules/@lmnr-ai/lmnr/dist/index.js

Example error message with Turbopack

 ⚠ ./node_modules/.pnpm/@opentelemetry+instrumentation@0.57.2_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node
Package import-in-the-middle can't be external
The request import-in-the-middle matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install import-in-the-middle from the project directory.


 ⚠ ./node_modules/.pnpm/@opentelemetry+instrumentation@0.56.0_@opentelemetry+api@1.9.0/node_modules/@opentelemetry/instrumentation/build/esm/platform/node
Package require-in-the-middle can't be external
The request require-in-the-middle matches serverExternalPackages (or the default list).
The request could not be resolved by Node.js from the project directory.
Packages that should be external need to be installed in the project directory, so they can be resolved from the output files.
Try to install it into the project directory by running npm install require-in-the-middle from the project directory.

Summary

Add a subsection within the Next.js section that describes

Verification

Syntax highlighter for MDX

Tasks

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • Formatting issues have been fixed (run pnpm prettier-fix in the project root)

Future Work

Related Issues

@dinmukhamedm dinmukhamedm marked this pull request as ready for review May 9, 2025 12:44
@nicoalbanese nicoalbanese merged commit a149b66 into vercel:main May 13, 2025
6 of 7 checks passed
lgrammel pushed a commit that referenced this pull request May 16, 2025
## Background

Like many other OpenTelemetry instrumentations, Laminar depends on
`@opentelemetry/instrumentation`, which, in turn, depends on
`require-in-the-middle` and `import-in-the-middle`. Importing and
initializing Laminar inside Next.js `instrumentation.ts` file causes
Next.js to try resolving these two packages, but fails, and results in:

- Laminar not being able to send traces. This is because unlike many
other instrumentation libraries, Laminar is not intrusive and does not
set its tracer provider globally (so that others, e.g. `@vercel/otel`
can set theirs).
- Error messages (see below)

We have tried many different things to debug, including bundling Laminar
differently, shipping those two packages within Laminar as `noExternal`,
adding a separate entrypoint in our package for Next.js, but nothing
seems to have worked.

The only thing that's worked was adding `@lmnr-ai/lmnr` in
`serverExternalPackages` in
[next.config](https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages).

## Summary

Add a subsection within the Next.js section that describes
lgrammel added a commit that referenced this pull request May 16, 2025
…6350)

## Background

Like many other OpenTelemetry instrumentations, Laminar depends on
`@opentelemetry/instrumentation`, which, in turn, depends on
`require-in-the-middle` and `import-in-the-middle`. Importing and
initializing Laminar inside Next.js `instrumentation.ts` file causes
Next.js to try resolving these two packages, but fails, and results in:

- Laminar not being able to send traces. This is because unlike many
other instrumentation libraries, Laminar is not intrusive and does not
set its tracer provider globally (so that others, e.g. `@vercel/otel`
can set theirs).
- Error messages (see below)

We have tried many different things to debug, including bundling Laminar
differently, shipping those two packages within Laminar as `noExternal`,
adding a separate entrypoint in our package for Next.js, but nothing
seems to have worked.

The only thing that's worked was adding `@lmnr-ai/lmnr` in
`serverExternalPackages` in

[next.config](https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages).

## Summary

Add a subsection within the Next.js section that describes

Co-authored-by: Dinmukhamed Mailibay <47117969+dinmukhamedm@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants