From a570f174d22c9359f616155eed68898d8a324170 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 31 Mar 2024 11:24:32 +0300 Subject: [PATCH 01/15] feat!(instrumentation): remove moudleExports generic type from instrumentation registration --- .../package.json | 1 + .../src/instrumentation.ts | 8 +++--- .../instrumentationNodeModuleDefinition.ts | 12 ++++----- .../src/instrumentationNodeModuleFile.ts | 8 +++--- .../src/platform/node/instrumentation.ts | 17 ++++++------ .../src/types.ts | 18 ++++++------- .../test/common/Instrumentation.test.ts | 2 +- .../test/node/InstrumentationBase.test.ts | 26 +++++++++---------- .../tsconfig.esm.json | 3 +++ .../tsconfig.esnext.json | 3 +++ .../tsconfig.json | 3 +++ package-lock.json | 2 ++ 12 files changed, 58 insertions(+), 45 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/package.json b/experimental/packages/opentelemetry-instrumentation/package.json index e2a1785aa4..b882aabf55 100644 --- a/experimental/packages/opentelemetry-instrumentation/package.json +++ b/experimental/packages/opentelemetry-instrumentation/package.json @@ -86,6 +86,7 @@ "@babel/preset-env": "7.22.20", "@opentelemetry/api": "1.8.0", "@opentelemetry/api-logs": "0.47.0", + "@opentelemetry/sdk-logs": "0.49.1", "@opentelemetry/sdk-metrics": "1.22.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index ed619bd139..6f0342294e 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -35,7 +35,7 @@ import { /** * Base abstract internal class for instrumenting node and web plugins */ -export abstract class InstrumentationAbstract +export abstract class InstrumentationAbstract implements Instrumentation { protected _config: InstrumentationConfig; @@ -116,7 +116,7 @@ export abstract class InstrumentationAbstract * * @returns an array of {@link InstrumentationModuleDefinition} */ - public getModuleDefinitions(): InstrumentationModuleDefinition[] { + public getModuleDefinitions(): InstrumentationModuleDefinition[] { const initResult = this.init() ?? []; if (!Array.isArray(initResult)) { return [initResult]; @@ -172,7 +172,7 @@ export abstract class InstrumentationAbstract * methods. */ protected abstract init(): - | InstrumentationModuleDefinition - | InstrumentationModuleDefinition[] + | InstrumentationModuleDefinition + | InstrumentationModuleDefinition[] | void; } diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts index e45a943a7f..a9f693de6c 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts @@ -19,16 +19,16 @@ import { InstrumentationModuleFile, } from './types'; -export class InstrumentationNodeModuleDefinition - implements InstrumentationModuleDefinition +export class InstrumentationNodeModuleDefinition + implements InstrumentationModuleDefinition { - files: InstrumentationModuleFile[]; + files: InstrumentationModuleFile[]; constructor( public name: string, public supportedVersions: string[], - public patch?: (exports: T, moduleVersion?: string) => T, - public unpatch?: (exports: T, moduleVersion?: string) => void, - files?: InstrumentationModuleFile[] + public patch?: (exports: any, moduleVersion?: string) => any, + public unpatch?: (exports: any, moduleVersion?: string) => void, + files?: InstrumentationModuleFile[] ) { this.files = files || []; } diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts index edbe8ba72e..f59f8e68a6 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts @@ -17,15 +17,15 @@ import { InstrumentationModuleFile } from './types'; import { normalize } from './platform/index'; -export class InstrumentationNodeModuleFile - implements InstrumentationModuleFile +export class InstrumentationNodeModuleFile + implements InstrumentationModuleFile { public name: string; constructor( name: string, public supportedVersions: string[], - public patch: (moduleExports: T, moduleVersion?: string) => T, - public unpatch: (moduleExports?: T, moduleVersion?: string) => void + public patch: (moduleExports: any, moduleVersion?: string) => any, + public unpatch: (moduleExports?: any, moduleVersion?: string) => void ) { this.name = normalize(name); } diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index c639bc8bd4..55953b560d 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -34,11 +34,11 @@ import { Hook } from 'require-in-the-middle'; /** * Base abstract class for instrumenting node plugins */ -export abstract class InstrumentationBase +export abstract class InstrumentationBase extends InstrumentationAbstract implements types.Instrumentation { - private _modules: InstrumentationModuleDefinition[]; + private _modules: InstrumentationModuleDefinition[]; private _hooks: (Hooked | Hook)[] = []; private _requireInTheMiddleSingleton: RequireInTheMiddleSingleton = RequireInTheMiddleSingleton.getInstance(); @@ -57,7 +57,7 @@ export abstract class InstrumentationBase modules = [modules]; } - this._modules = (modules as InstrumentationModuleDefinition[]) || []; + this._modules = (modules as InstrumentationModuleDefinition[]) || []; if (this._modules.length === 0) { diag.debug( @@ -142,7 +142,7 @@ export abstract class InstrumentationBase }; private _warnOnPreloadedModules(): void { - this._modules.forEach((module: InstrumentationModuleDefinition) => { + this._modules.forEach((module: InstrumentationModuleDefinition) => { const { name } = module; try { const resolvedModule = require.resolve(name); @@ -171,7 +171,7 @@ export abstract class InstrumentationBase } private _onRequire( - module: InstrumentationModuleDefinition, + module: InstrumentationModuleDefinition, exports: T, name: string, baseDir?: string | void @@ -213,7 +213,8 @@ export abstract class InstrumentationBase return supportedFileInstrumentations.reduce((patchedExports, file) => { file.moduleExports = patchedExports; if (this._enabled) { - return file.patch(patchedExports, module.moduleVersion); + // patch signature is not typed, so we cast it assuming it's correct + return file.patch(patchedExports, module.moduleVersion) as T; } return patchedExports; }, exports); @@ -244,7 +245,7 @@ export abstract class InstrumentationBase for (const module of this._modules) { const hookFn: HookFn = (exports, name, baseDir) => { return this._onRequire( - module as unknown as InstrumentationModuleDefinition, + module as unknown as InstrumentationModuleDefinition, exports, name, baseDir @@ -252,7 +253,7 @@ export abstract class InstrumentationBase }; const onRequire: OnRequireFn = (exports, name, baseDir) => { return this._onRequire( - module as unknown as InstrumentationModuleDefinition, + module as unknown as InstrumentationModuleDefinition, exports, name, baseDir diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 3ef070f829..554faa20bc 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -82,29 +82,29 @@ export interface ShimWrapped extends Function { __original: Function; } -export interface InstrumentationModuleFile { +export interface InstrumentationModuleFile { /** Name of file to be patched with relative path */ name: string; - moduleExports?: T; + moduleExports?: unknown; /** Supported version this file */ supportedVersions: string[]; /** Method to patch the instrumentation */ - patch(moduleExports: T, moduleVersion?: string): T; + patch(moduleExports: unknown, moduleVersion?: string): unknown; /** Method to patch the instrumentation */ /** Method to unpatch the instrumentation */ - unpatch(moduleExports?: T, moduleVersion?: string): void; + unpatch(moduleExports?: unknown, moduleVersion?: string): void; } -export interface InstrumentationModuleDefinition { +export interface InstrumentationModuleDefinition { /** Module name or path */ name: string; - moduleExports?: T; + moduleExports?: any; /** Instrumented module version */ moduleVersion?: string; @@ -114,14 +114,14 @@ export interface InstrumentationModuleDefinition { /** Module internal files to be patched */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - files: InstrumentationModuleFile[]; + 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; + patch?: (moduleExports: any, moduleVersion?: string) => any; /** Method to unpatch the instrumentation */ - unpatch?: (moduleExports: T, moduleVersion?: string) => void; + unpatch?: (moduleExports: any, moduleVersion?: string) => void; } diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts index fde0c2c34e..b35ccf504f 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts @@ -135,7 +135,7 @@ describe('BaseInstrumentation', () => { }); describe('getModuleDefinitions', () => { - const moduleDefinition: InstrumentationModuleDefinition = { + const moduleDefinition: InstrumentationModuleDefinition = { name: 'foo', patch: moduleExports => {}, unpatch: moduleExports => {}, diff --git a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts index b9597c65d8..a26d2c818a 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/node/InstrumentationBase.test.ts @@ -56,7 +56,7 @@ describe('InstrumentationBase', () => { const instrumentationModule = { name: CORE_MODULE, patch: modulePatchSpy as unknown, - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -79,7 +79,7 @@ describe('InstrumentationBase', () => { const instrumentationModule = { name: CORE_MODULE, patch: modulePatchSpy as unknown, - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -117,7 +117,7 @@ describe('InstrumentationBase', () => { supportedVersions: [`^${MODULE_VERSION}`], name: MODULE_NAME, patch: modulePatchSpy as unknown, - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -140,7 +140,7 @@ describe('InstrumentationBase', () => { supportedVersions: [`^${MODULE_VERSION}`, WILDCARD_VERSION], name: MODULE_NAME, patch: modulePatchSpy as unknown, - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -186,7 +186,7 @@ describe('InstrumentationBase', () => { patch: filePatchSpy as unknown, }, ], - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -218,7 +218,7 @@ describe('InstrumentationBase', () => { patch: filePatchSpy as unknown, }, ], - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -262,7 +262,7 @@ describe('InstrumentationBase', () => { patch: filePatchSpy as unknown, }, ], - } as InstrumentationModuleDefinition; + } as InstrumentationModuleDefinition; // @ts-expect-error access internal property for testing instrumentation._onRequire( @@ -293,15 +293,15 @@ describe('InstrumentationBase', () => { type Exports = Record; type ExportsPatched = Exports & { __patched?: boolean }; const moduleName = 'net'; - class TestInstrumentation extends InstrumentationBase { + class TestInstrumentation extends InstrumentationBase { constructor() { super('@opentelemetry/instrumentation-net-test', '0.0.0', { enabled: false, }); } - init(): InstrumentationNodeModuleDefinition[] { + init(): InstrumentationNodeModuleDefinition[] { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( moduleName, ['*'], (exports: ExportsPatched) => { @@ -335,15 +335,15 @@ describe('InstrumentationBase', () => { type ExportsPatched = Exports & { __patched?: boolean }; const moduleName = 'absolutePathTestFixture'; const fileName = path.join(__dirname, 'fixtures', `${moduleName}.js`); - class TestInstrumentation extends InstrumentationBase { + class TestInstrumentation extends InstrumentationBase { constructor() { super('@opentelemetry/instrumentation-absolute-path-test', '0.0.0', { enabled: false, }); } - init(): InstrumentationNodeModuleDefinition[] { + init(): InstrumentationNodeModuleDefinition[] { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( fileName, ['*'], undefined, diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json index 5affe32c2b..cfaf0186b5 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json @@ -17,6 +17,9 @@ }, { "path": "../api-logs" + }, + { + "path": "../sdk-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json index dae4bfa399..624c5e0796 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json @@ -17,6 +17,9 @@ }, { "path": "../api-logs" + }, + { + "path": "../sdk-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.json index 5da185276f..759962f549 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.json @@ -18,6 +18,9 @@ }, { "path": "../api-logs" + }, + { + "path": "../sdk-logs" } ] } diff --git a/package-lock.json b/package-lock.json index 6cc7166559..4d2c249ee1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3119,6 +3119,7 @@ "@babel/preset-env": "7.22.20", "@opentelemetry/api": "1.8.0", "@opentelemetry/api-logs": "0.47.0", + "@opentelemetry/sdk-logs": "0.49.1", "@opentelemetry/sdk-metrics": "1.22.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -41870,6 +41871,7 @@ "@babel/preset-env": "7.22.20", "@opentelemetry/api": "1.8.0", "@opentelemetry/api-logs": "0.47.0", + "@opentelemetry/sdk-logs": "0.49.1", "@opentelemetry/sdk-metrics": "1.22.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", From ab46f4a434125a37d654284c6f46cc80f64e08e2 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 31 Mar 2024 11:31:57 +0300 Subject: [PATCH 02/15] fix: lint --- .../opentelemetry-instrumentation/src/instrumentation.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index 6f0342294e..851b38c231 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -35,9 +35,7 @@ import { /** * Base abstract internal class for instrumenting node and web plugins */ -export abstract class InstrumentationAbstract - implements Instrumentation -{ +export abstract class InstrumentationAbstract implements Instrumentation { protected _config: InstrumentationConfig; private _tracer: Tracer; From 0fd1edc80811aa62fba0736dc9700e8e2fa89439 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 31 Mar 2024 11:33:42 +0300 Subject: [PATCH 03/15] chore: add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c68dec71a..da9a788372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :boom: Breaking Change +* feat!(instrumentation): remove moudleExports generic type from instrumentation registration [#4598](https://github.com/open-telemetry/opentelemetry-js/pull/4598) @blumamir + ### :rocket: (Enhancement) * perf(sdk-trace-base): do not allocate arrays if resource has no pending async attributes From 594c0270388e8fdda267621635bd274db0efab1d Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 31 Mar 2024 11:44:17 +0300 Subject: [PATCH 04/15] fix: core instrumentations --- .../src/fetch.ts | 4 +--- .../src/instrumentation.ts | 2 +- .../src/http.ts | 18 +++++++++--------- .../src/xhr.ts | 2 +- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts b/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts index 1f80bfd953..edf6f50cf7 100644 --- a/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts +++ b/experimental/packages/opentelemetry-instrumentation-fetch/src/fetch.ts @@ -72,9 +72,7 @@ export interface FetchInstrumentationConfig extends InstrumentationConfig { /** * This class represents a fetch plugin for auto instrumentation */ -export class FetchInstrumentation extends InstrumentationBase< - Promise -> { +export class FetchInstrumentation extends InstrumentationBase { readonly component: string = 'fetch'; readonly version: string = VERSION; moduleName = this.component; diff --git a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts index 3a04c24e1f..ca66e27878 100644 --- a/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation-grpc/src/instrumentation.ts @@ -92,7 +92,7 @@ export class GrpcInstrumentation extends InstrumentationBase { init() { return [ - new InstrumentationNodeModuleDefinition( + new InstrumentationNodeModuleDefinition( '@grpc/grpc-js', ['1.*'], (moduleExports, version) => { diff --git a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts index 1bc56cb499..e73a601de2 100644 --- a/experimental/packages/opentelemetry-instrumentation-http/src/http.ts +++ b/experimental/packages/opentelemetry-instrumentation-http/src/http.ts @@ -63,7 +63,7 @@ import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions'; /** * Http instrumentation instrumentation for Opentelemetry */ -export class HttpInstrumentation extends InstrumentationBase { +export class HttpInstrumentation extends InstrumentationBase { /** keep track on spans not ended */ private readonly _spanNotEnded: WeakSet = new WeakSet(); private _headerCapture; @@ -104,18 +104,18 @@ export class HttpInstrumentation extends InstrumentationBase { } init(): [ - InstrumentationNodeModuleDefinition, - InstrumentationNodeModuleDefinition, + InstrumentationNodeModuleDefinition, + InstrumentationNodeModuleDefinition, ] { return [this._getHttpsInstrumentation(), this._getHttpInstrumentation()]; } private _getHttpInstrumentation() { const version = process.versions.node; - return new InstrumentationNodeModuleDefinition( + return new InstrumentationNodeModuleDefinition( 'http', ['*'], - moduleExports => { + (moduleExports: Http): Http => { this._diag.debug(`Applying patch for http@${version}`); if (isWrapped(moduleExports.request)) { this._unwrap(moduleExports, 'request'); @@ -143,7 +143,7 @@ export class HttpInstrumentation extends InstrumentationBase { ); return moduleExports; }, - moduleExports => { + (moduleExports: Http) => { if (moduleExports === undefined) return; this._diag.debug(`Removing patch for http@${version}`); @@ -156,10 +156,10 @@ export class HttpInstrumentation extends InstrumentationBase { private _getHttpsInstrumentation() { const version = process.versions.node; - return new InstrumentationNodeModuleDefinition( + return new InstrumentationNodeModuleDefinition( 'https', ['*'], - moduleExports => { + (moduleExports: Https): Https => { this._diag.debug(`Applying patch for https@${version}`); if (isWrapped(moduleExports.request)) { this._unwrap(moduleExports, 'request'); @@ -187,7 +187,7 @@ export class HttpInstrumentation extends InstrumentationBase { ); return moduleExports; }, - moduleExports => { + (moduleExports: Https) => { if (moduleExports === undefined) return; this._diag.debug(`Removing patch for https@${version}`); diff --git a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts index c430d4ba3e..4d1e11df70 100644 --- a/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts +++ b/experimental/packages/opentelemetry-instrumentation-xml-http-request/src/xhr.ts @@ -81,7 +81,7 @@ export interface XMLHttpRequestInstrumentationConfig /** * This class represents a XMLHttpRequest plugin for auto instrumentation */ -export class XMLHttpRequestInstrumentation extends InstrumentationBase { +export class XMLHttpRequestInstrumentation extends InstrumentationBase { readonly component: string = 'xml-http-request'; readonly version: string = VERSION; moduleName = this.component; From 6745618465c464267295d0f6fae0e8298b7a1f0c Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 31 Mar 2024 14:44:21 +0300 Subject: [PATCH 05/15] docs: update README with the change --- .../packages/opentelemetry-instrumentation/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/README.md b/experimental/packages/opentelemetry-instrumentation/README.md index 39ddaeab9f..5ff6b11bfa 100644 --- a/experimental/packages/opentelemetry-instrumentation/README.md +++ b/experimental/packages/opentelemetry-instrumentation/README.md @@ -36,7 +36,7 @@ export class MyInstrumentation extends InstrumentationBase { * the plugin should patch multiple modules or versions. */ protected init() { - const module = new InstrumentationNodeModuleDefinition( + const module = new InstrumentationNodeModuleDefinition( 'module_name_to_be_patched', ['1.*'], this._onPatchMain, @@ -63,8 +63,8 @@ export class MyInstrumentation extends InstrumentationBase { this._unwrap(moduleExports, 'mainMethodName'); } - private _addPatchingMethod(): InstrumentationNodeModuleFile { - const file = new InstrumentationNodeModuleFile( + private _addPatchingMethod(): InstrumentationNodeModuleFile { + const file = new InstrumentationNodeModuleFile( 'module_name_to_be_patched/src/some_file.js', this._onPatchMethodName, this._onUnPatchMethodName, From d5774e70e7655925435aba4b2fd633ad4dbe1b18 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:26:45 +0300 Subject: [PATCH 06/15] Update experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts Co-authored-by: Marc Pichler --- .../src/platform/node/instrumentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index 55953b560d..a9f35e4c52 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -245,7 +245,7 @@ export abstract class InstrumentationBase for (const module of this._modules) { const hookFn: HookFn = (exports, name, baseDir) => { return this._onRequire( - module as unknown as InstrumentationModuleDefinition, + module, exports, name, baseDir From d766c66f0ae70603510f0f35cb93b37365a14035 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:26:56 +0300 Subject: [PATCH 07/15] Update experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts Co-authored-by: Marc Pichler --- .../src/platform/node/instrumentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index a9f35e4c52..35f66e6ae7 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -253,7 +253,7 @@ export abstract class InstrumentationBase }; const onRequire: OnRequireFn = (exports, name, baseDir) => { return this._onRequire( - module as unknown as InstrumentationModuleDefinition, + module, exports, name, baseDir From b269187638f91a6861cec0bdcc99080b0684e699 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:27:20 +0300 Subject: [PATCH 08/15] Update CHANGELOG.md Co-authored-by: Marc Pichler --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 373925e822..3e5028c000 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :boom: Breaking Change -* feat!(instrumentation): remove moudleExports generic type from instrumentation registration [#4598](https://github.com/open-telemetry/opentelemetry-js/pull/4598) @blumamir +* feat!(instrumentation): remove moduleExports generic type from instrumentation registration [#4598](https://github.com/open-telemetry/opentelemetry-js/pull/4598) @blumamir + * breaking for instrumentation authors that depend on + - `InstrumentationBase` + - `InstrumentationNodeModuleDefinition` + - `InstrumentationNodeModuleFile` ### :rocket: (Enhancement) From 34a3a447d86e42fc89dda3bd55c8edc246eda746 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:29:52 +0300 Subject: [PATCH 09/15] chore: lint --- .../src/platform/node/instrumentation.ts | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts index 35f66e6ae7..4768822d08 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/platform/node/instrumentation.ts @@ -244,20 +244,10 @@ export abstract class InstrumentationBase this._warnOnPreloadedModules(); for (const module of this._modules) { const hookFn: HookFn = (exports, name, baseDir) => { - return this._onRequire( - module, - exports, - name, - baseDir - ); + return this._onRequire(module, exports, name, baseDir); }; const onRequire: OnRequireFn = (exports, name, baseDir) => { - return this._onRequire( - module, - exports, - name, - baseDir - ); + return this._onRequire(module, exports, name, baseDir); }; // `RequireInTheMiddleSingleton` does not support absolute paths. From 78fc0163a73125ef54932b2719c907a8227c88a9 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:34:00 +0300 Subject: [PATCH 10/15] revert: sdk-logs in tsconfig --- .../packages/opentelemetry-instrumentation/tsconfig.esm.json | 3 --- .../opentelemetry-instrumentation/tsconfig.esnext.json | 3 --- .../packages/opentelemetry-instrumentation/tsconfig.json | 3 --- 3 files changed, 9 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json index cfaf0186b5..5affe32c2b 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json @@ -17,9 +17,6 @@ }, { "path": "../api-logs" - }, - { - "path": "../sdk-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json index 624c5e0796..dae4bfa399 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json @@ -17,9 +17,6 @@ }, { "path": "../api-logs" - }, - { - "path": "../sdk-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.json index 759962f549..5da185276f 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.json @@ -18,9 +18,6 @@ }, { "path": "../api-logs" - }, - { - "path": "../sdk-logs" } ] } From 19ea29ca699db98520181822551ef761f598aaf7 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sun, 14 Apr 2024 10:39:04 +0300 Subject: [PATCH 11/15] chore: lint markdown --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e5028c000..b056ecb7fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,10 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :boom: Breaking Change * feat!(instrumentation): remove moduleExports generic type from instrumentation registration [#4598](https://github.com/open-telemetry/opentelemetry-js/pull/4598) @blumamir - * breaking for instrumentation authors that depend on - - `InstrumentationBase` - - `InstrumentationNodeModuleDefinition` - - `InstrumentationNodeModuleFile` + * breaking for instrumentation authors that depend on + * `InstrumentationBase` + * `InstrumentationNodeModuleDefinition` + * `InstrumentationNodeModuleFile` ### :rocket: (Enhancement) From fdac3a3897a2da5dcebc38ed480e1c0e5bb653d8 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Wed, 17 Apr 2024 19:45:58 +0300 Subject: [PATCH 12/15] Apply suggestions from code review Co-authored-by: Jamie Danielson --- .../packages/opentelemetry-instrumentation/src/types.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 554faa20bc..088ce96a5a 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -104,6 +104,7 @@ export interface InstrumentationModuleDefinition { /** Module name or path */ name: string; + // eslint-disable-next-line @typescript-eslint/no-explicit-any moduleExports?: any; /** Instrumented module version */ @@ -120,8 +121,10 @@ export interface InstrumentationModuleDefinition { includePrerelease?: boolean; /** Method to patch the instrumentation */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any patch?: (moduleExports: any, moduleVersion?: string) => any; /** Method to unpatch the instrumentation */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any unpatch?: (moduleExports: any, moduleVersion?: string) => void; } From 59f263f6aad783721d99c31c38e19bb11095fabd Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Wed, 17 Apr 2024 19:48:58 +0300 Subject: [PATCH 13/15] Update experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts Co-authored-by: Jamie Danielson --- .../src/instrumentationNodeModuleFile.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts index f59f8e68a6..b821552b9f 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleFile.ts @@ -24,7 +24,9 @@ export class InstrumentationNodeModuleFile constructor( name: string, public supportedVersions: string[], + // eslint-disable-next-line @typescript-eslint/no-explicit-any public patch: (moduleExports: any, moduleVersion?: string) => any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any public unpatch: (moduleExports?: any, moduleVersion?: string) => void ) { this.name = normalize(name); From 499cbc187b478eb68b12a51edcda026c5f5d71c7 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Wed, 17 Apr 2024 19:49:09 +0300 Subject: [PATCH 14/15] Update experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts Co-authored-by: Jamie Danielson --- .../src/instrumentationNodeModuleDefinition.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts index a9f693de6c..2d17ce3cf3 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentationNodeModuleDefinition.ts @@ -26,7 +26,9 @@ export class InstrumentationNodeModuleDefinition constructor( public name: string, public supportedVersions: string[], + // eslint-disable-next-line @typescript-eslint/no-explicit-any public patch?: (exports: any, moduleVersion?: string) => any, + // eslint-disable-next-line @typescript-eslint/no-explicit-any public unpatch?: (exports: any, moduleVersion?: string) => void, files?: InstrumentationModuleFile[] ) { From 4c7ca0e270a55edd142a568c705f58a07177a2ca Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Wed, 17 Apr 2024 19:52:02 +0300 Subject: [PATCH 15/15] fix: remove unrelevant eslint ignore --- experimental/packages/opentelemetry-instrumentation/src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 088ce96a5a..680cffce89 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -114,7 +114,6 @@ export interface InstrumentationModuleDefinition { 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 */