Skip to content

docs(observability): say a commonjs build on nest 12 needs the loader hook too - #3681

Merged
kamilmysliwiec merged 1 commit into
nestjs:masterfrom
thekhegay:docs-otel-cjs-loader
Oct 30, 2026
Merged

kamilmysliwiec merged 1 commit into
nestjs:masterfrom
thekhegay:docs-otel-cjs-loader

Conversation

@thekhegay

Copy link
Copy Markdown
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

OpenTelemetry page says the loader flag is only needed for ES module build. On Nest 12 CommonJS build (nest new --type cjs) still loads @nestjs/* as ES modules (@nestjs/platform-express is "type": "module" and does import express from 'express'), and --require hook only sees require(). So with CommonJS commands from the page Express is not patched, there are no instrumentation-express spans and HTTP span is POST instead of POST /orders. Same with importing instrumentation.ts on first line of main.ts

What is the new behavior?

Hint says CommonJS build on Nest 12 needs the loader flag as well, and the first-line import note says it is not enough for Express there. Checked on Nest 12.3.2 with auto-instrumentations-node 0.82.0 and sdk-node 0.300.0, Node 24: adding --experimental-loader=@opentelemetry/instrumentation/hook.mjs to CommonJS command brings Express spans and POST /orders back

Does this PR introduce a breaking change?

  • Yes
  • No

@kamilmysliwiec
kamilmysliwiec merged commit e668b39 into nestjs:master Oct 30, 2026
5 checks passed
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