From ff8da9dcc1293d3e8fd9ee3f2cf9aaa590572317 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:18:37 -0800 Subject: [PATCH 01/10] Allow LoggerProvider to be specified in Instrumentations --- .../package.json | 4 +++- .../src/autoLoader.ts | 11 ++++++++-- .../src/autoLoaderUtils.ts | 9 ++++++-- .../src/instrumentation.ts | 22 +++++++++++++++++-- .../src/types.ts | 6 ++++- .../src/types_internal.ts | 4 +++- .../test/common/autoLoader.test.ts | 21 +++++++++++++++++- 7 files changed, 67 insertions(+), 10 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/package.json b/experimental/packages/opentelemetry-instrumentation/package.json index da40052d0b..9337482762 100644 --- a/experimental/packages/opentelemetry-instrumentation/package.json +++ b/experimental/packages/opentelemetry-instrumentation/package.json @@ -78,11 +78,13 @@ "shimmer": "^1.2.1" }, "peerDependencies": { - "@opentelemetry/api": "^1.3.0" + "@opentelemetry/api": "^1.3.0", + "@opentelemetry/api-logs": "^0.45.1" }, "devDependencies": { "@babel/core": "7.23.3", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.45.1", "@opentelemetry/sdk-metrics": "1.18.1", "@types/mocha": "10.0.4", "@types/node": "18.6.5", diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts index c6a052c6c9..5473d28917 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts @@ -15,6 +15,7 @@ */ import { trace, metrics } from '@opentelemetry/api'; +import { logs } from '@opentelemetry/api-logs'; import { disableInstrumentations, enableInstrumentations, @@ -36,10 +37,16 @@ export function registerInstrumentations( ); const tracerProvider = options.tracerProvider || trace.getTracerProvider(); const meterProvider = options.meterProvider || metrics.getMeterProvider(); + const loggerProvider = options.loggerProvider || logs.getLoggerProvider(); - enableInstrumentations(instrumentations, tracerProvider, meterProvider); + enableInstrumentations( + instrumentations, + tracerProvider, + meterProvider, + loggerProvider + ); return () => { disableInstrumentations(instrumentations); }; -} +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts index 3dc1927214..3337925595 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts @@ -17,6 +17,7 @@ import { TracerProvider, MeterProvider } from '@opentelemetry/api'; import { Instrumentation } from './types'; import { AutoLoaderResult, InstrumentationOption } from './types_internal'; +import { LoggerProvider } from '@opentelemetry/api-logs'; /** * Parses the options and returns instrumentations, node plugins and @@ -52,7 +53,8 @@ export function parseInstrumentationOptions( export function enableInstrumentations( instrumentations: Instrumentation[], tracerProvider?: TracerProvider, - meterProvider?: MeterProvider + meterProvider?: MeterProvider, + loggerProvider?: LoggerProvider ): void { for (let i = 0, j = instrumentations.length; i < j; i++) { const instrumentation = instrumentations[i]; @@ -62,6 +64,9 @@ export function enableInstrumentations( if (meterProvider) { instrumentation.setMeterProvider(meterProvider); } + if (loggerProvider) { + instrumentation.setLoggerProvider(loggerProvider); + } // instrumentations have been already enabled during creation // so enable only if user prevented that by setting enabled to false // this is to prevent double enabling but when calling register all @@ -80,4 +85,4 @@ export function disableInstrumentations( instrumentations: Instrumentation[] ): void { instrumentations.forEach(instrumentation => instrumentation.disable()); -} +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index 4b729fd439..5be75d208a 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -24,6 +24,7 @@ import { Tracer, TracerProvider, } from '@opentelemetry/api'; +import { Logger, LoggerProvider, logs } from '@opentelemetry/api-logs'; import * as shimmer from 'shimmer'; import { InstrumentationModuleDefinition } from './platform/node'; import * as types from './types'; @@ -38,6 +39,7 @@ export abstract class InstrumentationAbstract private _tracer: Tracer; private _meter: Meter; + private _logger: Logger; protected _diag: DiagLogger; constructor( @@ -55,8 +57,8 @@ export abstract class InstrumentationAbstract }); this._tracer = trace.getTracer(instrumentationName, instrumentationVersion); - this._meter = metrics.getMeter(instrumentationName, instrumentationVersion); + this._logger = logs.getLogger(instrumentationName, instrumentationVersion); this._updateMetricInstruments(); } @@ -87,6 +89,22 @@ export abstract class InstrumentationAbstract this._updateMetricInstruments(); } + /* Returns logger */ + protected get logger(): Logger { + return this._logger; + } + + /** + * Sets LoggerProvider to this plugin + * @param loggerProvider + */ + public setLoggerProvider(loggerProvider: LoggerProvider): void { + this._logger = loggerProvider.getLogger( + this.instrumentationName, + this.instrumentationVersion + ); + } + /** * Sets the new metric instruments with the current Meter. */ @@ -137,4 +155,4 @@ export abstract class InstrumentationAbstract | InstrumentationModuleDefinition | InstrumentationModuleDefinition[] | void; -} +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 837f096792..41074ca214 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -15,6 +15,7 @@ */ import { TracerProvider, MeterProvider } from '@opentelemetry/api'; +import { LoggerProvider } from '@opentelemetry/api-logs'; /** Interface Instrumentation to apply patch. */ export interface Instrumentation { @@ -43,6 +44,9 @@ export interface Instrumentation { /** Method to set meter provider */ setMeterProvider(meterProvider: MeterProvider): void; + /** Method to set logger provider */ + setLoggerProvider(loggerProvider: LoggerProvider): void; + /** Method to set instrumentation config */ setConfig(config: InstrumentationConfig): void; @@ -76,4 +80,4 @@ export interface ShimWrapped extends Function { __unwrap: Function; // eslint-disable-next-line @typescript-eslint/ban-types __original: Function; -} +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts index 2cff387711..f4829f4801 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts @@ -17,6 +17,7 @@ import { TracerProvider, MeterProvider } from '@opentelemetry/api'; import { InstrumentationBase } from './platform'; import { Instrumentation } from './types'; +import { LoggerProvider } from '@opentelemetry/api-logs'; export type InstrumentationOption = | typeof InstrumentationBase @@ -32,4 +33,5 @@ export interface AutoLoaderOptions { instrumentations?: InstrumentationOption[]; tracerProvider?: TracerProvider; meterProvider?: MeterProvider; -} + loggerProvider?: LoggerProvider; +} \ No newline at end of file diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts index aa8c5582a3..27dcbb83b5 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts @@ -24,6 +24,7 @@ import { import * as assert from 'assert'; import * as sinon from 'sinon'; import { InstrumentationBase, registerInstrumentations } from '../../src'; +import { Logger, LoggerOptions, LoggerProvider } from '@opentelemetry/api-logs'; class DummyTracerProvider implements TracerProvider { getTracer(name: string, version?: string): Tracer { @@ -37,6 +38,12 @@ class DummyMeterProvider implements MeterProvider { } } +class DummyLoggerProvider implements LoggerProvider { + getLogger(name: string, version?: string, options?: LoggerOptions): Logger { + throw new Error('not implemented'); + } +} + class FooInstrumentation extends InstrumentationBase { init() { return []; @@ -63,17 +70,21 @@ describe('autoLoader', () => { let enableSpy: sinon.SinonSpy; let setTracerProviderSpy: sinon.SinonSpy; let setMeterProviderSpy: sinon.SinonSpy; + let setLoggerProviderSpy: sinon.SinonSpy; const tracerProvider = new DummyTracerProvider(); const meterProvider = new DummyMeterProvider(); + const loggerProvider = new DummyLoggerProvider(); beforeEach(() => { instrumentation = new FooInstrumentation('foo', '1', {}); enableSpy = sinon.spy(instrumentation, 'enable'); setTracerProviderSpy = sinon.stub(instrumentation, 'setTracerProvider'); setMeterProviderSpy = sinon.stub(instrumentation, 'setMeterProvider'); + setLoggerProviderSpy = sinon.stub(instrumentation, 'setLoggerProvider'); unload = registerInstrumentations({ instrumentations: [instrumentation], tracerProvider, meterProvider, + loggerProvider, }); }); @@ -96,10 +107,12 @@ describe('autoLoader', () => { enableSpy = sinon.spy(instrumentation, 'enable'); setTracerProviderSpy = sinon.stub(instrumentation, 'setTracerProvider'); setMeterProviderSpy = sinon.stub(instrumentation, 'setMeterProvider'); + setLoggerProviderSpy = sinon.stub(instrumentation, 'setLoggerProvider'); unload = registerInstrumentations({ instrumentations: [instrumentation], tracerProvider, meterProvider, + loggerProvider, }); assert.strictEqual(enableSpy.callCount, 1); }); @@ -119,6 +132,12 @@ describe('autoLoader', () => { assert.ok(setMeterProviderSpy.lastCall.args[0] === meterProvider); assert.strictEqual(setMeterProviderSpy.lastCall.args.length, 1); }); + + it('should set LoggerProvider', () => { + assert.strictEqual(setLoggerProviderSpy.callCount, 1); + assert.ok(setLoggerProviderSpy.lastCall.args[0] === loggerProvider); + assert.strictEqual(setLoggerProviderSpy.lastCall.args.length, 1); + }); }); }); -}); +}); \ No newline at end of file From c050c40a6c925b8562c97db12d753f54cfbbd7e8 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:25:43 -0800 Subject: [PATCH 02/10] Update --- .../opentelemetry-instrumentation/tsconfig.esm.json | 3 +++ .../opentelemetry-instrumentation/tsconfig.esnext.json | 3 +++ .../packages/opentelemetry-instrumentation/tsconfig.json | 3 +++ package-lock.json | 9 ++++++--- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json index a673b46483..5affe32c2b 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esm.json @@ -14,6 +14,9 @@ }, { "path": "../../../packages/sdk-metrics" + }, + { + "path": "../api-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json index f70e767a6e..dae4bfa399 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.esnext.json @@ -14,6 +14,9 @@ }, { "path": "../../../packages/sdk-metrics" + }, + { + "path": "../api-logs" } ] } diff --git a/experimental/packages/opentelemetry-instrumentation/tsconfig.json b/experimental/packages/opentelemetry-instrumentation/tsconfig.json index 668bce7426..5da185276f 100644 --- a/experimental/packages/opentelemetry-instrumentation/tsconfig.json +++ b/experimental/packages/opentelemetry-instrumentation/tsconfig.json @@ -15,6 +15,9 @@ }, { "path": "../../../packages/sdk-metrics" + }, + { + "path": "../api-logs" } ] } diff --git a/package-lock.json b/package-lock.json index 5d179a92a5..d121590ab1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1928,7 +1928,7 @@ "version": "0.45.1", "license": "Apache-2.0", "dependencies": { - "@types/shimmer": "^1.0.5", + "@types/shimmer": "^1.0.2", "import-in-the-middle": "1.4.2", "require-in-the-middle": "^7.1.1", "semver": "^7.5.2", @@ -1937,6 +1937,7 @@ "devDependencies": { "@babel/core": "7.23.3", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.45.1", "@opentelemetry/sdk-metrics": "1.18.1", "@types/mocha": "10.0.4", "@types/node": "18.6.5", @@ -1969,7 +1970,8 @@ "node": ">=14" }, "peerDependencies": { - "@opentelemetry/api": "^1.3.0" + "@opentelemetry/api": "^1.3.0", + "@opentelemetry/api-logs": "^0.45.1" } }, "experimental/packages/opentelemetry-instrumentation-fetch": { @@ -39962,11 +39964,12 @@ "requires": { "@babel/core": "7.23.3", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.45.1", "@opentelemetry/sdk-metrics": "1.18.1", "@types/mocha": "10.0.4", "@types/node": "18.6.5", "@types/semver": "7.5.5", - "@types/shimmer": "^1.0.5", + "@types/shimmer": "^1.0.2", "@types/sinon": "10.0.20", "@types/webpack-env": "1.16.3", "babel-loader": "8.3.0", From 04fd7dedd9e446ba7713a74da9dc3cd308e36891 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:48:19 -0800 Subject: [PATCH 03/10] Lint --- experimental/CHANGELOG.md | 2 ++ .../packages/opentelemetry-instrumentation/src/autoLoader.ts | 2 +- .../opentelemetry-instrumentation/src/autoLoaderUtils.ts | 2 +- .../opentelemetry-instrumentation/src/instrumentation.ts | 2 +- .../packages/opentelemetry-instrumentation/src/types.ts | 2 +- .../opentelemetry-instrumentation/src/types_internal.ts | 2 +- .../test/common/autoLoader.test.ts | 2 +- 7 files changed, 8 insertions(+), 6 deletions(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index b9935e26c5..9f0f593541 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) +* feat(instrumentation): allow LoggerProvider to be specified in Instrumentations [#4314](https://github.com/open-telemetry/opentelemetry-js/pull/4314) @hectorhdzg + ### :bug: (Bug Fix) * fix(sdk-logs): avoid map attribute set when count limit exceeded diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts index 5473d28917..266648bcf6 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoader.ts @@ -49,4 +49,4 @@ export function registerInstrumentations( return () => { disableInstrumentations(instrumentations); }; -} \ No newline at end of file +} diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts index 3337925595..7890fede46 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts @@ -85,4 +85,4 @@ export function disableInstrumentations( instrumentations: Instrumentation[] ): void { instrumentations.forEach(instrumentation => instrumentation.disable()); -} \ No newline at end of file +} diff --git a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts index 5be75d208a..f63c30242b 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/instrumentation.ts @@ -155,4 +155,4 @@ export abstract class InstrumentationAbstract | InstrumentationModuleDefinition | InstrumentationModuleDefinition[] | void; -} \ No newline at end of file +} diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index 41074ca214..95c3054fd7 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -80,4 +80,4 @@ export interface ShimWrapped extends Function { __unwrap: Function; // eslint-disable-next-line @typescript-eslint/ban-types __original: Function; -} \ No newline at end of file +} diff --git a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts index f4829f4801..ad71821fc3 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types_internal.ts @@ -34,4 +34,4 @@ export interface AutoLoaderOptions { tracerProvider?: TracerProvider; meterProvider?: MeterProvider; loggerProvider?: LoggerProvider; -} \ No newline at end of file +} diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts index 27dcbb83b5..e5532f2e5f 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/autoLoader.test.ts @@ -140,4 +140,4 @@ describe('autoLoader', () => { }); }); }); -}); \ No newline at end of file +}); From 28095e1c2ef49aeea91af94fa61a95426567947e Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Mon, 4 Dec 2023 13:32:02 -0800 Subject: [PATCH 04/10] Add test --- .../test/common/Instrumentation.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts index be53d1ca59..4c57f4f6e2 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts @@ -22,6 +22,7 @@ import { } from '../../src'; import { MeterProvider } from '@opentelemetry/sdk-metrics'; +import { LoggerProvider } from '@opentelemetry/sdk-logs'; interface TestInstrumentationConfig extends InstrumentationConfig { isActive?: boolean; @@ -90,6 +91,21 @@ describe('BaseInstrumentation', () => { }); }); + describe('setLoggerProvider', () => { + it('should get a logger from provider', () => { + let called = true; + class TestLoggerProvider extends LoggerProvider { + override getLogger(name: any, version?: any, options?: any) { + called = true; + return super.getLogger(name, version, options); + } + } + instrumentation = new TestInstrumentation(); + instrumentation.setLoggerProvider(new TestLoggerProvider()); + assert.strictEqual(called, true); + }); + }); + describe('getConfig', () => { it('should return instrumentation config', () => { const instrumentation: Instrumentation = new TestInstrumentation({ From c0bccdc701f2cd04eccb55fd3579822536c104e4 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 2 Jan 2024 17:10:12 -0800 Subject: [PATCH 05/10] npm i --- package-lock.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index d85efac063..266fc6c499 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3113,6 +3113,7 @@ "devDependencies": { "@babel/core": "7.23.6", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.46.0", "@opentelemetry/sdk-metrics": "1.19.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -3146,7 +3147,7 @@ }, "peerDependencies": { "@opentelemetry/api": "^1.3.0", - "@opentelemetry/api-logs": "^0.45.1" + "@opentelemetry/api-logs": "^0.46.0" } }, "experimental/packages/opentelemetry-instrumentation-fetch": { @@ -40757,6 +40758,7 @@ "requires": { "@babel/core": "7.23.6", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.46.0", "@opentelemetry/sdk-metrics": "1.19.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", From 235116ba37c09f23b4baa23f6c47290c0e86e9f9 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Wed, 10 Jan 2024 15:16:38 -0800 Subject: [PATCH 06/10] Update changelog --- experimental/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index 3a08f5b73a..c9b09b21b3 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -13,6 +13,8 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) +* feat(instrumentation): allow LoggerProvider to be specified in Instrumentations [#4314](https://github.com/open-telemetry/opentelemetry-js/pull/4314) @hectorhdzg + ### :bug: (Bug Fix) * fix(instrumentation): use caret range on import-in-the-middle [#4380](https://github.com/open-telemetry/opentelemetry-js/pull/4380) @pichlermarc @@ -36,7 +38,6 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) -* feat(instrumentation): allow LoggerProvider to be specified in Instrumentations [#4314](https://github.com/open-telemetry/opentelemetry-js/pull/4314) @hectorhdzg * feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord ### :bug: (Bug Fix) From 250a44044d03a49dec4ceadd760b0dfef3701c58 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 16 Jan 2024 10:58:48 -0800 Subject: [PATCH 07/10] npm i --- package-lock.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/package-lock.json b/package-lock.json index 8428c3cfe6..482c55518e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "hasInstallScript": true, "license": "Apache-2.0", "workspaces": [ + "api", "packages/*", "experimental/packages/*", "experimental/examples/*", @@ -3112,6 +3113,7 @@ "devDependencies": { "@babel/core": "7.23.6", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.47.0", "@opentelemetry/sdk-metrics": "1.20.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -40757,6 +40759,7 @@ "requires": { "@babel/core": "7.23.6", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.47.0", "@opentelemetry/sdk-metrics": "1.20.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", From 964a6a44fdf847ed6557d5528d46386eb5594919 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:13:36 -0800 Subject: [PATCH 08/10] marking setLoggerProvider as optional --- .../packages/opentelemetry-instrumentation/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/types.ts b/experimental/packages/opentelemetry-instrumentation/src/types.ts index fb4ef4a4a1..3ef070f829 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/types.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/types.ts @@ -45,7 +45,7 @@ export interface Instrumentation { setMeterProvider(meterProvider: MeterProvider): void; /** Method to set logger provider */ - setLoggerProvider(loggerProvider: LoggerProvider): void; + setLoggerProvider?(loggerProvider: LoggerProvider): void; /** Method to set instrumentation config */ setConfig(config: InstrumentationConfig): void; From 415bfa35fd659cf78c2be8efee54475d7c179a68 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 16 Jan 2024 13:21:16 -0800 Subject: [PATCH 09/10] Add check for possible undefined method --- .../opentelemetry-instrumentation/src/autoLoaderUtils.ts | 2 +- .../test/common/Instrumentation.test.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts index 7890fede46..91ef7a653d 100644 --- a/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts +++ b/experimental/packages/opentelemetry-instrumentation/src/autoLoaderUtils.ts @@ -64,7 +64,7 @@ export function enableInstrumentations( if (meterProvider) { instrumentation.setMeterProvider(meterProvider); } - if (loggerProvider) { + if (loggerProvider && instrumentation.setLoggerProvider) { instrumentation.setLoggerProvider(loggerProvider); } // instrumentations have been already enabled during creation diff --git a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts index 4c57f4f6e2..126f4c0944 100644 --- a/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts +++ b/experimental/packages/opentelemetry-instrumentation/test/common/Instrumentation.test.ts @@ -101,7 +101,9 @@ describe('BaseInstrumentation', () => { } } instrumentation = new TestInstrumentation(); - instrumentation.setLoggerProvider(new TestLoggerProvider()); + if (instrumentation.setLoggerProvider) { + instrumentation.setLoggerProvider(new TestLoggerProvider()); + } assert.strictEqual(called, true); }); }); From abcf7972025397f4bfd1b9675319f57f64d1cce6 Mon Sep 17 00:00:00 2001 From: Hector Hernandez <39923391+hectorhdzg@users.noreply.github.com> Date: Tue, 30 Jan 2024 16:00:24 -0800 Subject: [PATCH 10/10] npm i --- package-lock.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/package-lock.json b/package-lock.json index a49495b084..d122f5a19c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3117,6 +3117,7 @@ "@babel/core": "7.23.6", "@babel/preset-env": "7.22.20", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.47.0", "@opentelemetry/sdk-metrics": "1.21.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -3875,6 +3876,18 @@ "node": ">= 8" } }, + "experimental/packages/opentelemetry-instrumentation/node_modules/@opentelemetry/api-logs": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.47.0.tgz", + "integrity": "sha512-AR6UOVcWZkuibLR/7/OecYJasncAf6VstNV/KT5qHq1HShVFmJetcgim0KMog/ON23yHZQjT9GPVTwB0FEhPQA==", + "dev": true, + "dependencies": { + "@opentelemetry/api": "^1.0.0" + }, + "engines": { + "node": ">=14" + } + }, "experimental/packages/opentelemetry-instrumentation/node_modules/@webpack-cli/configtest": { "version": "2.1.1", "dev": true, @@ -40337,6 +40350,7 @@ "@babel/core": "7.23.6", "@babel/preset-env": "7.22.20", "@opentelemetry/api": "1.7.0", + "@opentelemetry/api-logs": "0.47.0", "@opentelemetry/sdk-metrics": "1.21.0", "@types/mocha": "10.0.6", "@types/node": "18.6.5", @@ -40371,6 +40385,15 @@ "webpack-merge": "5.10.0" }, "dependencies": { + "@opentelemetry/api-logs": { + "version": "0.47.0", + "resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.47.0.tgz", + "integrity": "sha512-AR6UOVcWZkuibLR/7/OecYJasncAf6VstNV/KT5qHq1HShVFmJetcgim0KMog/ON23yHZQjT9GPVTwB0FEhPQA==", + "dev": true, + "requires": { + "@opentelemetry/api": "^1.0.0" + } + }, "@webpack-cli/configtest": { "version": "2.1.1", "dev": true,