feat: ESM support for instrumentation#3698
Conversation
also, `this` doesnt work outside scope with esm
iitm added to ritm singleton tests stubbed to keep current behavior Co-authored-by: Purvi Kanal <kanal.purvi@gmail.com>
doesn't currently work with iitm register
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3698 +/- ##
==========================================
+ Coverage 93.19% 93.22% +0.02%
==========================================
Files 298 293 -5
Lines 9057 8883 -174
Branches 1864 1825 -39
==========================================
- Hits 8441 8281 -160
+ Misses 616 602 -14
|
|
Thank you for working on this! :) |
|
@JamieDanielson my personal superheroine!!! |
|
omg, wahoo, y'all got it over the line @JamieDanielson and @pkanal!!! |
That's very kind but I definitely cannot take all this credit. It's taken a lot of work from a lot of people, and this latest iteration has a ton of work done by my colleague Purvi (@pkanal) - it just only allows one name on the PR in GH 😃 |
|
I'll also re-link the comment that Qard made over my PR #2846 (comment) which is still relevant to this one |
- pins versions in example app - node 20 support disclaimer - re-export hook.mjs file functions 😍
|
I don't have the ability to rerun workflows but I think the current status check failures may be related to some service issues GitHub is having today, as I've had similar-looking fails on other workflows that resolved when rerunning. |
|
@JamieDanielson seems my PR created a conflict in readme. Please update the limitations accordingly because once this PR is merge one limitation is gone (besides for node 20) 🎉 |
pichlermarc
left a comment
There was a problem hiding this comment.
Looks good, thank you for putting in all the work. 🙂
As this is quite a significant change, I'll wait for another approval before merging this.
| As the ESM module loader from NodeJS is experimental, so is our support for it. Feel free to provide feedback or report issues about it. | ||
|
|
||
| **Note**: ESM Instrumentation is not yet supported for Node 20. | ||
|
|
There was a problem hiding this comment.
Please update the limitations section below which tells ECMA script modules (using import) is not supported as of now.
There was a problem hiding this comment.
what does this mean? How can one use ESM without import?
There was a problem hiding this comment.
It means that the limitations section requires changes in this PR because it removes one of them.
Before this PR ESM/import was not supported and only CJS/require worked.
Th limitation with bundlers stays.
There was a problem hiding this comment.
huh, super, thanks for the clarification :) a panic mode was already about to arise :D
Co-authored-by: Purvi Kanal <purvikanal@honeycomb.io>
Which problem is this PR solving?
Updates / Closes #1946
Short description of the changes
ECMAScript Modules (ESM) have become the standard module system for Node.js, but CommonJS (CJS) is also still used widely, so we need a way to enable instrumentation for both module systems. This is built upon / supersedes the work of previous PRs and discussions (#2640, #2763, #2846) .
import-in-the-middle(IITM) as another hook, to be used instead ofrequire-in-the-middle(RITM) when the argument is passed to use the new hook--experimental-loader=@opentelemetry/instrumentation/hook.mjs(alternative option includes the ability to use--experimental-loader=import-in-the-middle/hook.mjswith an added dependency onimport-in-the-middle)npm run test:esmand as part ofnpm run testesm-http-tsbuilt in TypeScript that compiles to ESM and shows http instrumentation workingprocess.versionto preventundefinedversion for ESM.Type of change
How Has This Been Tested?
Checklist: