-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use module.register(...)
in recommended bootstrap code for ESM support
#4933
Comments
Regarding usage with CommonJS (CJS) codeIt would be nice to have one recommended way to bootstrap OTel, to eliminate user confusion. Currently, setting up OTel when using ESM (often it isn't clear if a given user is using ESM or CJS) requires the extra Moving to
So... until those are our base support Node.js versions, we will still have to talk about / document a bootstrap module that uses CJS and |
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 14 days. |
Hi, since Node v22 is now the official LTS (well, it will be tomorrow), and since it now supports |
Just noting a couple things based on having looked at #5097 for loading typescript files specifically:
|
@acidoxee Currently OTel JS supports back to node v14, so until the base supported Node.js version is v22 we cannot rely on @jpmunz I'm pretty ignorant to what typescript path aliases are for. Correct me if I'm wrong: supporting them in OTel bootstrap code is independent of whether we use |
FYI: The autoinstrumentation.{js,mjs} file used by the OTel Operator might soon be using |
@trentm correct I was just mentioning in regards to some of the bullets related to .ts files, e.g.
|
Quick note re |
Yup using |
Hope this is the right place, I am facing a similar issue here with a Eventually I landed on #4437 and https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/esm-support.md#instrumentation-hook-required-for-esm Is there any recommendation to get this to work with a next app building with |
@zacharyblasczyk Let's please keep debugging Next.js instrumentation on a separate issue. While Issues with instrumenting Next.js servers could also be unrelated to the ESM hook. |
The current advice for limited ESM support is to use
--experimental-loader=...
. Ultimately we should move towards recommendingmodule.register(...)
usage instead, because it is on the path to being non-experimental in Node.js core (https://nodejs.org/api/module.html#moduleregisterspecifier-parenturl-options).To use this, bootstrap code will move to something like:
telemetry.mjs
And it would be run like one of the following.
Notes:
module.register()
and--import
, which requires^18.19.0 || ^20.6.0 || >=22
. One option would be document this as a minimum requirement at the top of our "experimental ESM support" and then mention that for some earlier versions of node there is the "unsupported, forever-experimental, unrecommended" (or some working) option using--experimental-loader=
. Then we can shunt all that complexity to a separate section.createAddHookMessageChannel
thing (feat: Optionally only wrap modules hooked in--import
nodejs/import-in-the-middle#146) from import-in-the-middle that will almost certainly be coming soon, and that we'll want to use..mjs
ext for the bootstrap file. There are some subtleties here..mjs
makes it clear the file is ESM code, so that it doesn't depend on a "type" entry in the package.json file..ts
option (see run option 3 above). This may be fine.--import
does support getting a CJS file, so even if "tsconfig.json" emits CJS, then--import ...
will work../instrumentation.ts
?if (typeof register === 'function') { ... }
. Then we could document this one-true-path for all users -- with a callout to a separate "If you are using ESM code ..." section that explains those limitations.Originally posted by @trentm in #4845 (comment)
The text was updated successfully, but these errors were encountered: