feat(node): Register ESM patching hooks in init for supported Node.js versions#11933
Merged
feat(node): Register ESM patching hooks in init for supported Node.js versions#11933
init for supported Node.js versions#11933Conversation
added 2 commits
May 7, 2024 10:47
s1gr1d
approved these changes
May 7, 2024
mydea
reviewed
May 7, 2024
packages/node/src/sdk/init.ts
Outdated
| // Register hook was added in v20.6.0 and v18.19.0 | ||
| if (nodeMajor > 22 || (nodeMajor === 20 && nodeMinor >= 6) || (nodeMajor === 18 && nodeMinor >= 19)) { | ||
| // @ts-expect-error register is available in these versions & import.meta is allowed | ||
| moduleModule.register('@opentelemetry/instrumentation/hook.mjs', import.meta.url); |
Member
There was a problem hiding this comment.
just to be sure, does it matter if this is registered twice?
Contributor
Author
There was a problem hiding this comment.
Ok, I tested this and registering twice is a problem. We get around this for ourselves by only registering once and tracking with a global whether we have already registered.
I can see this becoming a problem if people have their own hooks registered already. I currently don't see a straight forward way of detecting this so for now we will just have to document this behaviour.
We should keep an eye open though for automatic detection.
added 2 commits
May 8, 2024 08:01
added 3 commits
May 8, 2024 10:15
Contributor
size-limit report 📦
|
added 2 commits
May 8, 2024 12:25
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
To avoid needing to have two
--requireflags when running a Node process (one for the ESM loader hooks, one forSentry.init()), we can useSentry.init()itself to register the ESM patching hooks.We
registerwhen we are on a compatible Node.js versionloaderflag on older versions if the the hook wasn't registered yet