From 49597241f60f9d00ae4504fe5fd128e2fd74a0e6 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 21 Apr 2022 09:01:53 -0700 Subject: [PATCH 1/3] feat(ConsoleSpanExporter): export span links --- .../src/export/ConsoleSpanExporter.ts | 3 ++- .../common/export/ConsoleSpanExporter.test.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts b/packages/opentelemetry-sdk-trace-base/src/export/ConsoleSpanExporter.ts index 60f803c5d0..57baa62d3a 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 { attributes: span.attributes, status: span.status, events: span.events, + links: span.links }; } @@ -78,7 +79,7 @@ export class ConsoleSpanExporter implements SpanExporter { done?: (result: ExportResult) => void ): void { for (const span of spans) { - console.log(this._exportInfo(span)); + console.dir(this._exportInfo(span), { depth: 3 }); } if (done) { return done({ code: ExportResultCode.SUCCESS }); 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 8e5e40adfb..b3477ae510 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 @@ -14,6 +14,10 @@ * limitations under the License. */ +import { + SpanContext, + TraceFlags, +} from '@opentelemetry/api'; import { AlwaysOnSampler } from '@opentelemetry/core'; import * as assert from 'assert'; import * as sinon from 'sinon'; @@ -53,7 +57,15 @@ describe('ConsoleSpanExporter', () => { new SimpleSpanProcessor(consoleExporter) ); - const span = basicTracerProvider.getTracer('default').startSpan('foo'); + const tracer = basicTracerProvider.getTracer('default'); + const context: SpanContext = { + traceId: 'a3cda95b652f4a1592b449d5929fda1b', + spanId: '5e0c63257de34c92', + traceFlags: TraceFlags.SAMPLED, + }; + const span = tracer.startSpan('foo', { + links: [ { context, attributes: { anAttr: 'aValue' } } ] + }); span.addEvent('foobar'); span.end(); @@ -70,6 +82,7 @@ describe('ConsoleSpanExporter', () => { 'events', 'id', 'kind', + 'links', 'name', 'parentId', 'status', @@ -80,7 +93,7 @@ describe('ConsoleSpanExporter', () => { assert.ok(firstSpan.name === 'foo'); assert.ok(firstEvent.name === 'foobar'); assert.ok(consoleSpan.id === firstSpan.spanContext().spanId); - assert.ok(keys === expectedKeys); + assert.ok(keys === expectedKeys, 'expectedKeys'); assert.ok(spyExport.calledOnce); }); From 00432f0fcbca1d18357b0e3616c433fe770f43cb Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 21 Apr 2022 09:27:55 -0700 Subject: [PATCH 2/3] test: update test case for change to console.dir --- .../test/common/export/ConsoleSpanExporter.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 b3477ae510..0a66b13fc2 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 @@ -30,16 +30,16 @@ import { /* eslint-disable no-console */ describe('ConsoleSpanExporter', () => { let consoleExporter: ConsoleSpanExporter; - let previousConsoleLog: any; + let previousConsoleDir: any; beforeEach(() => { - previousConsoleLog = console.log; - console.log = () => {}; + previousConsoleDir = console.dir; + console.dir = () => {}; consoleExporter = new ConsoleSpanExporter(); }); afterEach(() => { - console.log = previousConsoleLog; + console.dir = previousConsoleDir; }); describe('.export()', () => { @@ -50,7 +50,7 @@ describe('ConsoleSpanExporter', () => { }); consoleExporter = new ConsoleSpanExporter(); - const spyConsole = sinon.spy(console, 'log'); + const spyConsole = sinon.spy(console, 'dir'); const spyExport = sinon.spy(consoleExporter, 'export'); basicTracerProvider.addSpanProcessor( From 968b8b563e0ec1581dab34c8bda48bd9d3025217 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Thu, 21 Apr 2022 09:31:26 -0700 Subject: [PATCH 3/3] chore: changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58c9a285f2..821e11a2d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file. ### :rocket: (Enhancement) +* feat(ConsoleSpanExporter): export span links [#2917](https://github.com/open-telemetry/opentelemetry-js/pull/2917) @trentm + ### :bug: (Bug Fix) * fix: sanitize attributes inputs [#2881](https://github.com/open-telemetry/opentelemetry-js/pull/2881) @legendecas