diff --git a/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index f50cff4252..d03afadb93 100644 --- a/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -17,7 +17,7 @@ import * as types from '../../types'; import * as path from 'path'; import * as RequireInTheMiddle from 'require-in-the-middle'; -import * as semver from 'semver'; +import { satisfies } from 'semver'; import { InstrumentationAbstract } from '../../instrumentation'; import { InstrumentationModuleDefinition } from './types'; import { diag } from '@opentelemetry/api'; @@ -50,7 +50,7 @@ export abstract class InstrumentationBase if (this._modules.length === 0) { diag.warn( 'No modules instrumentation has been defined,' + - ' nothing will be patched' + ' nothing will be patched' ); } @@ -80,7 +80,7 @@ export abstract class InstrumentationBase // main module if ( typeof version === 'string' && - isSupported(module.supportedVersions, version) + isSupported(module.supportedVersions, version, module.includePrerelease) ) { if (typeof module.patch === 'function') { module.moduleExports = exports; @@ -93,7 +93,7 @@ export abstract class InstrumentationBase // internal file const files = module.files ?? []; const file = files.find(file => file.name === name); - if (file && isSupported(file.supportedVersions, version)) { + if (file && isSupported(file.supportedVersions, version, module.includePrerelease)) { file.moduleExports = exports; if (this._enabled) { return file.patch(exports, module.moduleVersion); @@ -167,8 +167,8 @@ export abstract class InstrumentationBase } } -function isSupported(supportedVersions: string[], version: string): boolean { +function isSupported(supportedVersions: string[], version: string, includePrerelease?: boolean): boolean { return supportedVersions.some(supportedVersion => { - return semver.satisfies(version, supportedVersion); + return satisfies(version, supportedVersion, { includePrerelease }); }); } diff --git a/packages/opentelemetry-instrumentation/src/platform/node/types.ts b/packages/opentelemetry-instrumentation/src/platform/node/types.ts index 972659bf00..c5ea980c30 100644 --- a/packages/opentelemetry-instrumentation/src/platform/node/types.ts +++ b/packages/opentelemetry-instrumentation/src/platform/node/types.ts @@ -47,6 +47,9 @@ export interface InstrumentationModuleDefinition { /** Module internal files to be patched */ files: InstrumentationModuleFile[]; + /** If set to true, the includePrerelease check will be included when calling semver.satisfies */ + includePrerelease?: boolean; + /** Method to patch the instrumentation */ patch?: (moduleExports: T, moduleVersion?: string) => T;