Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-telemetry/opentelemetry-js int…
Browse files Browse the repository at this point in the history
…o feat/host-detector
  • Loading branch information
rauno56 committed Apr 27, 2022
2 parents 8d89fbe + 60a17ee commit 326658b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
### :rocket: (Enhancement)

* feat(ConsoleSpanExporter): export span links [#2917](https://github.com/open-telemetry/opentelemetry-js/pull/2917) @trentm
* feat: warn when hooked module is already loaded [#2926](https://github.com/open-telemetry/opentelemetry-js/pull/2926) @nozik
* feat: implement HostDetector [#2921](https://github.com/open-telemetry/opentelemetry-js/pull/2921) @rauno56

### :bug: (Bug Fix)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ export abstract class InstrumentationBase<T = any>
}
}

private _warnOnPreloadedModules(): void {
this._modules.forEach((module: InstrumentationModuleDefinition<T>) => {
const { name } = module;
try {
const resolvedModule = require.resolve(name);
if (require.cache[resolvedModule]) {
// 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}`);
}
} catch {
// Module isn't available, we can simply skip
}
});
}

private _extractPackageVersion(baseDir: string): string | undefined {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -134,6 +149,7 @@ export abstract class InstrumentationBase<T = any>
return;
}

this._warnOnPreloadedModules();
for (const module of this._modules) {
this._hooks.push(
RequireInTheMiddle(
Expand Down

0 comments on commit 326658b

Please sign in to comment.