Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
* feat(sdk-trace-base): implement on ending in span processor [#6024](https://github.com/open-telemetry/opentelemetry-js/pull/6024) @majanjua-amzn
* note: this feature is experimental and subject to change

* chore(opentelemetry-instrumentation): improve `_warnOnPreloadedModules` function not to show warning logs when the module is not marked as loaded [#6095](https://github.com/open-telemetry/opentelemetry-js/pull/6095) @rlj1202

### :bug: Bug Fixes

### :books: Documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export abstract class InstrumentationBase<
const { name } = module;
try {
const resolvedModule = require.resolve(name);
if (require.cache[resolvedModule]) {
if (require.cache[resolvedModule]?.loaded) {
Copy link
Contributor

@david-luna david-luna Dec 10, 2025

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).

Copy link
Author

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})`
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good :)

// Module is already cached, which means the instrumentation hook might not work
this._diag.warn(
`Module ${name} has been loaded before ${this.instrumentationName} so it might not work, please initialize it before requiring ${name}`
Expand Down