-
Notifications
You must be signed in to change notification settings - Fork 978
chore(opentelemetry-instrumentation): improve _warnOnPreloadedModules function not to show warning logs when the module is not marked as loaded
#6095
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
base: main
Are you sure you want to change the base?
Conversation
|
|
b755cfa to
8ae3980
Compare
_warnOnPreloadedModules function not to show warning logs when the module is not marked as loaded
8ae3980 to
caab4e6
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6095 +/- ##
=======================================
Coverage 95.16% 95.16%
=======================================
Files 316 316
Lines 9226 9226
Branches 2082 2082
=======================================
Hits 8780 8780
Misses 446 446 🚀 New features to boost your workflow:
|
… function not to show warning logs when the module is not marked as loaded
caab4e6 to
7cbc531
Compare
| try { | ||
| const resolvedModule = require.resolve(name); | ||
| if (require.cache[resolvedModule]) { | ||
| if (require.cache[resolvedModule]?.loaded) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function gets called when enabling a instrumentation and we're not certain when this will happen. There is more than one way to register and enable instrumentations so I wonder if we can have a situation where we are enabling an instrumentation amid the load process of the instrumented module (and loaded ins not true yet).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then... just printing the information together might be enough like this:
this._diag.warn(
`Module ${name} has been loaded before ${this.instrumentationName} so it might not work, please initialize it before requiring ${name} (loaded = ${require.cache[resolvedModule]?.loaded ?? false})`
);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good :)
Which problem is this PR solving?
On ESM environment where ECMAScript module and CommonJS modules coexist, unnecessary module preload warning logs appear.
How Has This Been Tested?
Example:
graph TD; main.mjs-->a.mjs; main.mjs-->b.cjs; main.mjs-->d.mjs; main.mjs-->e.cjs; b.cjs-->c.cjs; e.cjs-->f.cjs;main.mjsvisited,b.cjsande.cjsappear in therequire.cacheasloaded = falsea.mjsvisited and loadedb.cjsvisited,c.cjsappears in therequire.cacheasloaded = falsec.cjsvisited and loadedb.cjsloadedd.mjsvisited and loadede.cjsvisited,f.cjsappears in therequire.cacheasloaded = falsef.cjsvisited and loadede.cjsloadedmain.mjsloadedSo to warn preloaded modules properly in ESM environment,
Module.loadedproperty should be considered.Checklist: