fix(opentelemetry-instrumentation): improve _warnOnPreloadedModules function not to show warning logs when the module is not marked as loaded#6095
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.70% 95.70%
=======================================
Files 364 364
Lines 11774 11774
Branches 2747 2747
=======================================
Hits 11268 11268
Misses 506 506 🚀 New features to boost your workflow:
|
… function not to show warning logs when the module is not marked as loaded
caab4e6 to
7cbc531
Compare
|
@rlj1202 I can see how this seems correct. Did you run into a specific example with real modules where you hit this? I quickly tried to come up with a reproduction case of _warnOnPreloadedModules warning with real Instrumentations, but I couldn't'. |
Yes! I will make a simple working example using real instrumentations with NestJS and share it within a week. |
|
https://stackblitz.com/edit/nestjs-typescript-starter-xtzvpxev?file=src%2Fmain.ts This is a minimal real-world instrumentation example with Nest.js. If you run this using But instrumentation has no problem. You can see the result from the console logs printed by In this example, I triggered the instrumentation code by importing import './instrument.js';
// ...However, if you inject instrumentation code like this as described in official documents: npx tsx --import ./src/instrument.ts ./src/main.tsYou can never see the warning message as before, and this is an expected result. (You need a different running environment than stackblitz) |
|
Thanks for the repro. Interesting. Here is what I roughly think is happening. import './instrument.js';
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module.js';
async function main() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
}
void main();
//# sourceMappingURL=main.js.mapThis file is ESM. Notice that Then So, I agree with the decision to only emit this "Module [name] has been loaded before ..." warning if |
trentm
left a comment
There was a problem hiding this comment.
LGTM, with a nit: let's call it a fix (not a "chore" in the "Features" changelog section).
_warnOnPreloadedModules function not to show warning logs when the module is not marked as loaded_warnOnPreloadedModules function not to show warning logs when the module is not marked as loaded
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: