From 0229f2c96a93f135b0c0e478b38fc10fabc443e7 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Fri, 5 Jul 2024 01:34:42 +0300 Subject: [PATCH 1/5] feat: print instrumentation library info with console span exporter --- .../src/export/ConsoleSpanExporter.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts index dcca6d23bf..3b6dc43f15 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts @@ -65,6 +65,7 @@ export class ConsoleSpanExporter implements SpanExporter { resource: { attributes: span.resource.attributes, }, + instrumentationLibrary: span.instrumentationLibrary, traceId: span.spanContext().traceId, parentId: span.parentSpanId, traceState: span.spanContext().traceState?.serialize(), From 021ed2f42572592a849549991c652688f0382732 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Fri, 5 Jul 2024 01:40:57 +0300 Subject: [PATCH 2/5] chore: add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 644972b950..864241462e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :rocket: (Enhancement) +* feat: print instrumentation library info with console span exporter [#4848](https://github.com/open-telemetry/opentelemetry-js/pull/4848) @blumamir + ### :bug: (Bug Fix) ### :books: (Refine Doc) From bf712ff9f4acdcad6e293d7db659cdd163fe157c Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Fri, 5 Jul 2024 01:50:20 +0300 Subject: [PATCH 3/5] test: fix tests for console span exporter --- .../test/common/export/ConsoleSpanExporter.test.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts index ab50d26b57..9b9df00289 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts @@ -55,7 +55,9 @@ describe('ConsoleSpanExporter', () => { new SimpleSpanProcessor(consoleExporter) ); - const tracer = basicTracerProvider.getTracer('default'); + const instrumentationLibraryName = '@opentelemetry/sdk-trace-base/test'; + const instrumentationLibraryVersion = '1.2.3'; + const tracer = basicTracerProvider.getTracer(instrumentationLibraryName, instrumentationLibraryVersion); const context: SpanContext = { traceId: 'a3cda95b652f4a1592b449d5929fda1b', spanId: '5e0c63257de34c92', @@ -80,6 +82,7 @@ describe('ConsoleSpanExporter', () => { 'duration', 'events', 'id', + 'instrumentationLibrary', 'kind', 'links', 'name', @@ -95,6 +98,8 @@ describe('ConsoleSpanExporter', () => { assert.ok(firstEvent.name === 'foobar'); assert.ok(consoleSpan.id === firstSpan.spanContext().spanId); assert.ok(keys === expectedKeys, 'expectedKeys'); + assert.ok(firstSpan.instrumentationLibrary.name === instrumentationLibraryName); + assert.ok(firstSpan.instrumentationLibrary.version === instrumentationLibraryVersion); assert.ok(spyExport.calledOnce); }); From 19cd5a539f7ee290ea776ead98b60fd8b68d8655 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sat, 13 Jul 2024 23:23:51 +0300 Subject: [PATCH 4/5] feat: instrumentation scope for both logs and spans --- .../src/export/ConsoleLogRecordExporter.ts | 1 + .../export/ConsoleLogRecordExporter.test.ts | 22 ++++++++++++++----- .../src/export/ConsoleSpanExporter.ts | 2 +- .../common/export/ConsoleSpanExporter.test.ts | 20 ++++++++++++----- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/experimental/packages/sdk-logs/src/export/ConsoleLogRecordExporter.ts b/experimental/packages/sdk-logs/src/export/ConsoleLogRecordExporter.ts index efc52f4d3f..74441d0098 100644 --- a/experimental/packages/sdk-logs/src/export/ConsoleLogRecordExporter.ts +++ b/experimental/packages/sdk-logs/src/export/ConsoleLogRecordExporter.ts @@ -55,6 +55,7 @@ export class ConsoleLogRecordExporter implements LogRecordExporter { resource: { attributes: logRecord.resource.attributes, }, + instrumentationScope: logRecord.instrumentationScope, timestamp: hrTimeToMicroseconds(logRecord.hrTime), traceId: logRecord.spanContext?.traceId, spanId: logRecord.spanContext?.spanId, diff --git a/experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts b/experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts index 383bceec0c..5a264a2074 100644 --- a/experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts +++ b/experimental/packages/sdk-logs/test/common/export/ConsoleLogRecordExporter.test.ts @@ -40,6 +40,8 @@ describe('ConsoleLogRecordExporter', () => { describe('export', () => { it('should export information about log record', () => { assert.doesNotThrow(() => { + const instrumentationScopeName = '@opentelemetry/sdk-logs/test'; + const instrumentationScopeVersion = '1.2.3'; const consoleExporter = new ConsoleLogRecordExporter(); const spyConsole = sinon.spy(console, 'dir'); const spyExport = sinon.spy(consoleExporter, 'export'); @@ -48,11 +50,13 @@ describe('ConsoleLogRecordExporter', () => { new SimpleLogRecordProcessor(consoleExporter) ); - provider.getLogger('default').emit({ - body: 'body1', - severityNumber: SeverityNumber.DEBUG, - severityText: 'DEBUG', - }); + provider + .getLogger(instrumentationScopeName, instrumentationScopeVersion) + .emit({ + body: 'body1', + severityNumber: SeverityNumber.DEBUG, + severityText: 'DEBUG', + }); const logRecords = spyExport.args[0]; const firstLogRecord = logRecords[0][0]; @@ -63,6 +67,7 @@ describe('ConsoleLogRecordExporter', () => { const expectedKeys = [ 'attributes', 'body', + 'instrumentationScope', 'resource', 'severityNumber', 'severityText', @@ -76,6 +81,13 @@ describe('ConsoleLogRecordExporter', () => { assert.ok(firstLogRecord.severityNumber === SeverityNumber.DEBUG); assert.ok(firstLogRecord.severityText === 'DEBUG'); assert.ok(keys === expectedKeys, 'expectedKeys'); + assert.ok( + firstLogRecord.instrumentationScope.name === instrumentationScopeName + ); + assert.ok( + firstLogRecord.instrumentationScope.version === + instrumentationScopeVersion + ); assert.ok(spyExport.calledOnce); }); diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts index 3b6dc43f15..16998aa1f2 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts @@ -65,7 +65,7 @@ export class ConsoleSpanExporter implements SpanExporter { resource: { attributes: span.resource.attributes, }, - instrumentationLibrary: span.instrumentationLibrary, + instrumentationScope: span.instrumentationLibrary, traceId: span.spanContext().traceId, parentId: span.parentSpanId, traceState: span.spanContext().traceState?.serialize(), diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts index 9b9df00289..c73f318fff 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/ConsoleSpanExporter.test.ts @@ -55,9 +55,12 @@ describe('ConsoleSpanExporter', () => { new SimpleSpanProcessor(consoleExporter) ); - const instrumentationLibraryName = '@opentelemetry/sdk-trace-base/test'; - const instrumentationLibraryVersion = '1.2.3'; - const tracer = basicTracerProvider.getTracer(instrumentationLibraryName, instrumentationLibraryVersion); + const instrumentationScopeName = '@opentelemetry/sdk-trace-base/test'; + const instrumentationScopeVersion = '1.2.3'; + const tracer = basicTracerProvider.getTracer( + instrumentationScopeName, + instrumentationScopeVersion + ); const context: SpanContext = { traceId: 'a3cda95b652f4a1592b449d5929fda1b', spanId: '5e0c63257de34c92', @@ -82,7 +85,7 @@ describe('ConsoleSpanExporter', () => { 'duration', 'events', 'id', - 'instrumentationLibrary', + 'instrumentationScope', 'kind', 'links', 'name', @@ -98,8 +101,13 @@ describe('ConsoleSpanExporter', () => { assert.ok(firstEvent.name === 'foobar'); assert.ok(consoleSpan.id === firstSpan.spanContext().spanId); assert.ok(keys === expectedKeys, 'expectedKeys'); - assert.ok(firstSpan.instrumentationLibrary.name === instrumentationLibraryName); - assert.ok(firstSpan.instrumentationLibrary.version === instrumentationLibraryVersion); + assert.ok( + firstSpan.instrumentationLibrary.name === instrumentationScopeName + ); + assert.ok( + firstSpan.instrumentationLibrary.version === + instrumentationScopeVersion + ); assert.ok(spyExport.calledOnce); }); From 6eec63ed51dbee8616a0ec5d4985faf1933e5d82 Mon Sep 17 00:00:00 2001 From: Amir Blum Date: Sat, 13 Jul 2024 23:29:03 +0300 Subject: [PATCH 5/5] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 864241462e..f456029408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :rocket: (Enhancement) -* feat: print instrumentation library info with console span exporter [#4848](https://github.com/open-telemetry/opentelemetry-js/pull/4848) @blumamir +* feat: include instrumentation scope info in console span and log record exporters [#4848](https://github.com/open-telemetry/opentelemetry-js/pull/4848) @blumamir ### :bug: (Bug Fix)