From bf307791194f04fec56e69cefaee1b615f966abf Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Mon, 20 Nov 2023 09:56:53 -0500 Subject: [PATCH] Do not export node-specific names --- .../src/index.ts | 9 +-- .../src/instrumentation.ts | 17 +++--- .../instrumentationNodeModuleDefinition.ts | 0 .../src/platform/browser/index.ts | 2 +- .../src/platform/index.ts | 8 +-- .../src/platform/node/index.ts | 6 -- .../src/platform/node/instrumentation.ts | 2 +- .../node/instrumentationNodeModuleFile.ts | 2 +- .../src/platform/node/types.ts | 59 ------------------- .../src/types.ts | 44 ++++++++++++++ .../test/node/InstrumentationBase.test.ts | 10 ++-- .../InstrumentationNodeModuleFile.test.ts | 2 +- 12 files changed, 65 insertions(+), 96 deletions(-) rename experimental/packages/opentelemetry-instrumentation/src/{platform/node => }/instrumentationNodeModuleDefinition.ts (100%) delete mode 100644 experimental/packages/opentelemetry-instrumentation/src/platform/node/types.ts diff --git a/experimental/packages/opentelemetry-instrumentation/src/index.ts b/experimental/packages/opentelemetry-instrumentation/src/index.ts index 5f9b47c138..9929671fe5 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/index.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/index.ts @@ -15,13 +15,8 @@ */ export * from './autoLoader'; -export { - InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationModuleFile, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, -} from './platform/index'; +export { InstrumentationBase } from './platform/index'; +export { InstrumentationNodeModuleDefinition } from './instrumentationNodeModuleDefinition'; 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 4b729fd439..4552f6dfab 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/node/instrumentationNodeModuleDefinition.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts similarity index 100% rename from experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleDefinition.ts rename to experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/browser/index.ts index 24c76056a1..0b238b42b8 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 1fc5f5e14a..81d3096252 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 d3df10491f..1e81931b2a 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/platform/node/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index 03d8f6ba37..a4c11498c9 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -26,7 +26,7 @@ import { } from './RequireInTheMiddleSingleton'; import type { HookFn } from 'import-in-the-middle'; import * as ImportInTheMiddle from 'import-in-the-middle'; -import { InstrumentationModuleDefinition } from './types'; +import { InstrumentationModuleDefinition } from '../../types'; import { diag } from '@opentelemetry/api'; import type { OnRequireFn } from 'require-in-the-middle'; import { Hook } from 'require-in-the-middle'; diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts index 574f17257e..e5d642e7d4 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentationNodeModuleFile.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { InstrumentationModuleFile } from './types'; +import { InstrumentationModuleFile } from '../../types'; import { normalize } from 'path'; export class InstrumentationNodeModuleFile diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/types.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/types.ts deleted file mode 100644 index 5cdfbc84c0..0000000000 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/types.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -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/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 837f096792..760e31165f 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -77,3 +77,47 @@ 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 b9597c65d8..1219516c39 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts @@ -17,12 +17,10 @@ import * as assert from 'assert'; import * as sinon from 'sinon'; import * as path from 'path'; -import { - InstrumentationBase, - InstrumentationModuleDefinition, - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleFile, -} from '../../src'; +import { InstrumentationBase } from '../../src'; +import { InstrumentationNodeModuleDefinition } from '../../src/instrumentationNodeModuleDefinition'; +import { InstrumentationNodeModuleFile } from '../../src/platform/node/instrumentationNodeModuleFile'; +import { InstrumentationModuleDefinition } from '../../src/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 1c7db12a44..214d4fe36a 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', () => {