Skip to content

Commit 2355717

Browse files
dyladanvmarchaud
andauthoredJul 17, 2021
chore: add includePrerelease option to instrumentation config (#2309)
Co-authored-by: Valentin Marchaud <contact@vmarchaud.fr>
1 parent 90e941a commit 2355717

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed
 

‎packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import * as types from '../../types';
1818
import * as path from 'path';
1919
import * as RequireInTheMiddle from 'require-in-the-middle';
20-
import * as semver from 'semver';
20+
import { satisfies } from 'semver';
2121
import { InstrumentationAbstract } from '../../instrumentation';
2222
import { InstrumentationModuleDefinition } from './types';
2323
import { diag } from '@opentelemetry/api';
@@ -50,7 +50,7 @@ export abstract class InstrumentationBase<T = any>
5050
if (this._modules.length === 0) {
5151
diag.warn(
5252
'No modules instrumentation has been defined,' +
53-
' nothing will be patched'
53+
' nothing will be patched'
5454
);
5555
}
5656

@@ -80,7 +80,7 @@ export abstract class InstrumentationBase<T = any>
8080
// main module
8181
if (
8282
typeof version === 'string' &&
83-
isSupported(module.supportedVersions, version)
83+
isSupported(module.supportedVersions, version, module.includePrerelease)
8484
) {
8585
if (typeof module.patch === 'function') {
8686
module.moduleExports = exports;
@@ -93,7 +93,7 @@ export abstract class InstrumentationBase<T = any>
9393
// internal file
9494
const files = module.files ?? [];
9595
const file = files.find(file => file.name === name);
96-
if (file && isSupported(file.supportedVersions, version)) {
96+
if (file && isSupported(file.supportedVersions, version, module.includePrerelease)) {
9797
file.moduleExports = exports;
9898
if (this._enabled) {
9999
return file.patch(exports, module.moduleVersion);
@@ -167,8 +167,8 @@ export abstract class InstrumentationBase<T = any>
167167
}
168168
}
169169

170-
function isSupported(supportedVersions: string[], version: string): boolean {
170+
function isSupported(supportedVersions: string[], version: string, includePrerelease?: boolean): boolean {
171171
return supportedVersions.some(supportedVersion => {
172-
return semver.satisfies(version, supportedVersion);
172+
return satisfies(version, supportedVersion, { includePrerelease });
173173
});
174174
}

‎packages/opentelemetry-instrumentation/src/platform/node/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export interface InstrumentationModuleDefinition<T> {
4747
/** Module internal files to be patched */
4848
files: InstrumentationModuleFile<any>[];
4949

50+
/** If set to true, the includePrerelease check will be included when calling semver.satisfies */
51+
includePrerelease?: boolean;
52+
5053
/** Method to patch the instrumentation */
5154
patch?: (moduleExports: T, moduleVersion?: string) => T;
5255

0 commit comments

Comments
 (0)
Please sign in to comment.