diff --git a/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index ba94ce1411..e31476a369 100644 --- a/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -59,22 +59,6 @@ export abstract class InstrumentationBase } } - private _isSupported(name: string, version: string): boolean { - for (const module of this._modules) { - if (module.name === name) { - if (!module.supportedVersions) { - return true; - } - - return module.supportedVersions.some(supportedVersion => { - return semver.satisfies(version, supportedVersion); - }); - } - } - - return false; - } - private _onRequire( module: InstrumentationModuleDefinition, exports: T, @@ -93,7 +77,10 @@ export abstract class InstrumentationBase module.moduleVersion = version; if (module.name === name) { // main module - if (typeof version === 'string' && this._isSupported(name, version)) { + if ( + typeof version === 'string' && + isSupported(module.supportedVersions, version) + ) { if (typeof module.patch === 'function') { module.moduleExports = exports; if (this._enabled) { @@ -105,12 +92,7 @@ export abstract class InstrumentationBase // internal file const files = module.files ?? []; const file = files.find(file => file.name === name); - if ( - file && - file.supportedVersions.some(supportedVersion => - semver.satisfies(version, supportedVersion) - ) - ) { + if (file && isSupported(file.supportedVersions, version)) { file.moduleExports = exports; if (this._enabled) { return file.patch(exports, module.moduleVersion); @@ -179,3 +161,9 @@ export abstract class InstrumentationBase } } } + +function isSupported(supportedVersions: string[], version: string): boolean { + return supportedVersions.some(supportedVersion => { + return semver.satisfies(version, supportedVersion); + }); +}