diff --git a/experimental/packages/opentelemetry-instrumentation/src/index.ts b/experimental/packages/opentelemetry-instrumentation/src/index.ts index 5f9b47c1380..8abbd000d66 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/index.ts @@ -15,13 +15,7 @@ */ export * from './autoLoader'; -export { - InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationModuleFile, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, -} from './platform/index'; +export { InstrumentationBase } from './platform/index'; export * from './types'; export * from './types_internal'; export * from './utils'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index 4b729fd4394..d7ca9ffd891 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -25,16 +25,19 @@ import { TracerProvider, } from '@opentelemetry/api'; import * as shimmer from 'shimmer'; -import { InstrumentationModuleDefinition } from './platform/node'; -import * as types from './types'; +import { + InstrumentationModuleDefinition, + Instrumentation, + InstrumentationConfig +} from './types'; /** * Base abstract internal class for instrumenting node and web plugins */ export abstract class InstrumentationAbstract - implements types.Instrumentation + implements Instrumentation { - protected _config: types.InstrumentationConfig; + protected _config: InstrumentationConfig; private _tracer: Tracer; private _meter: Meter; @@ -43,7 +46,7 @@ export abstract class InstrumentationAbstract constructor( public readonly instrumentationName: string, public readonly instrumentationVersion: string, - config: types.InstrumentationConfig = {} + config: InstrumentationConfig = {} ) { this._config = { enabled: true, @@ -95,7 +98,7 @@ export abstract class InstrumentationAbstract } /* Returns InstrumentationConfig */ - public getConfig(): types.InstrumentationConfig { + public getConfig(): InstrumentationConfig { return this._config; } @@ -103,7 +106,7 @@ export abstract class InstrumentationAbstract * Sets InstrumentationConfig to this plugin * @param InstrumentationConfig */ - public setConfig(config: types.InstrumentationConfig = {}): void { + public setConfig(config: InstrumentationConfig = {}): void { this._config = Object.assign({}, config); } diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts index 24c76056a19..0b238b42b8a 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts @@ -14,4 +14,4 @@ * limitations under the License. */ -export * from './instrumentation'; +export { InstrumentationBase } from './instrumentation'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts index 1fc5f5e14a6..81d30962522 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/index.ts @@ -14,10 +14,4 @@ * limitations under the License. */ -export { - InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationModuleFile, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, -} from './node'; +export { InstrumentationBase } from './node'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts index d3df10491f4..1e81931b2a0 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/index.ts @@ -14,9 +14,3 @@ * limitations under the License. */ export { InstrumentationBase } from './instrumentation'; -export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition'; -export { InstrumentationNodeModuleFile } from './instrumentationNodeModuleFile'; -export { - InstrumentationModuleDefinition, - InstrumentationModuleFile, -} from './types'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 837f096792b..60418a86b2a 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -77,3 +77,49 @@ export interface ShimWrapped extends Function { // eslint-disable-next-line @typescript-eslint/ban-types __original: Function; } + + +export interface InstrumentationModuleFile { + /** Name of file to be patched with relative path */ + name: string; + + moduleExports?: T; + + /** Supported version this file */ + supportedVersions: string[]; + + /** Method to patch the instrumentation */ + patch(moduleExports: T, moduleVersion?: string): T; + + /** Method to patch the instrumentation */ + + /** Method to unpatch the instrumentation */ + unpatch(moduleExports?: T, moduleVersion?: string): void; +} + +export interface InstrumentationModuleDefinition { + /** Module name or path */ + name: string; + + moduleExports?: T; + + /** Instrumented module version */ + moduleVersion?: string; + + /** Supported version of module */ + supportedVersions: string[]; + + /** Module internal files to be patched */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + 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; + + /** Method to unpatch the instrumentation */ + unpatch?: (moduleExports: T, moduleVersion?: string) => void; +} + diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts index b9597c65d85..49dd093640a 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts @@ -19,10 +19,10 @@ import * as sinon from 'sinon'; import * as path from 'path'; import { InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, } from '../../src'; +import { InstrumentationNodeModuleDefinition } from '../../src/platform/node/instrumentationNodeModuleDefinition'; +import { InstrumentationNodeModuleFile } from '../../src/platform/node/instrumentationNodeModuleFile'; +import { InstrumentationModuleDefinition } from '../../src/platform/node/types'; const MODULE_NAME = 'test-module'; const MODULE_FILE_NAME = 'test-module-file'; diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationNodeModuleFile.test.ts b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationNodeModuleFile.test.ts index 1c7db12a440..214d4fe36ab 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationNodeModuleFile.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationNodeModuleFile.test.ts @@ -16,7 +16,7 @@ import * as assert from 'assert'; import { normalize } from 'path'; -import { InstrumentationNodeModuleFile } from '../../src'; +import { InstrumentationNodeModuleFile } from '../../src/platform/node/instrumentationNodeModuleFile'; describe('InstrumentationNodeModuleFile', () => { it('should convert path', () => {