Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add includePrerelease option to instrumentation config #2309

Merged
merged 5 commits into from
Jul 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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