Skip to content

Commit

Permalink
cr comment
Browse files Browse the repository at this point in the history
  • Loading branch information
nozik committed Apr 26, 2022
1 parent 4b36beb commit 051b5a5
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export abstract class InstrumentationBase<T = any>
'No modules instrumentation has been defined,' +
' nothing will be patched'
);
} else {
this._warnOnPreloadedModules();
}

if (this._config.enabled) {
Expand All @@ -62,25 +60,18 @@ export abstract class InstrumentationBase<T = any>
}

private _warnOnPreloadedModules(): void {
const preloadedModules: string[] = [];
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
preloadedModules.push(name);
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
}
});

if (!preloadedModules.length) {
return;
}

this._diag.warn(`Some modules (${preloadedModules.join(', ')}) were already required when their respective plugin was loaded, some plugins might not work. Make sure the SDK is setup before you require in other modules.`);
}

private _extractPackageVersion(baseDir: string): string | undefined {
Expand Down Expand Up @@ -158,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 051b5a5

Please sign in to comment.