Skip to content

Commit

Permalink
chore: add includePrerelease option to instrumentation config (#2309)
Browse files Browse the repository at this point in the history
Co-authored-by: Valentin Marchaud <[email protected]>
  • Loading branch information
dyladan and vmarchaud authored Jul 17, 2021
1 parent 90e941a commit 2355717
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -50,7 +50,7 @@ export abstract class InstrumentationBase<T = any>
if (this._modules.length === 0) {
diag.warn(
'No modules instrumentation has been defined,' +
' nothing will be patched'
' nothing will be patched'
);
}

Expand Down Expand Up @@ -80,7 +80,7 @@ export abstract class InstrumentationBase<T = any>
// main module
if (
typeof version === 'string' &&
isSupported(module.supportedVersions, version)
isSupported(module.supportedVersions, version, module.includePrerelease)
) {
if (typeof module.patch === 'function') {
module.moduleExports = exports;
Expand All @@ -93,7 +93,7 @@ export abstract class InstrumentationBase<T = any>
// 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);
Expand Down Expand Up @@ -167,8 +167,8 @@ export abstract class InstrumentationBase<T = any>
}
}

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 });
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export interface InstrumentationModuleDefinition<T> {
/** Module internal files to be patched */
files: InstrumentationModuleFile<any>[];

/** 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;

Expand Down

0 comments on commit 2355717

Please sign in to comment.