Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ConsoleSpanExporter): export span links #2917

Merged
merged 5 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ConsoleSpanExporter implements SpanExporter {
attributes: span.attributes,
status: span.status,
events: span.events,
links: span.links
};
}

Expand All @@ -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 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -26,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()', () => {
Expand All @@ -46,14 +50,22 @@ 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(
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();

Expand All @@ -70,6 +82,7 @@ describe('ConsoleSpanExporter', () => {
'events',
'id',
'kind',
'links',
'name',
'parentId',
'status',
Expand All @@ -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);
});
Expand Down