Skip to content

Commit

Permalink
feat: include instrumentation scope info in console span and log reco…
Browse files Browse the repository at this point in the history
…rd exporters (open-telemetry#4848)

* feat: print instrumentation library info with console span exporter

* chore: add changelog

* test: fix tests for console span exporter

* feat: instrumentation scope for both logs and spans

* chore: update changelog
  • Loading branch information
blumamir authored and Zirak committed Sep 14, 2024
1 parent c250d2e commit 746ae3b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :rocket: (Enhancement)

* 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)

### :books: (Refine Doc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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];
Expand All @@ -63,6 +67,7 @@ describe('ConsoleLogRecordExporter', () => {
const expectedKeys = [
'attributes',
'body',
'instrumentationScope',
'resource',
'severityNumber',
'severityText',
Expand All @@ -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);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ConsoleSpanExporter implements SpanExporter {
resource: {
attributes: span.resource.attributes,
},
instrumentationScope: span.instrumentationLibrary,
traceId: span.spanContext().traceId,
parentId: span.parentSpanId,
traceState: span.spanContext().traceState?.serialize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ describe('ConsoleSpanExporter', () => {
new SimpleSpanProcessor(consoleExporter)
);

const tracer = basicTracerProvider.getTracer('default');
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',
Expand All @@ -80,6 +85,7 @@ describe('ConsoleSpanExporter', () => {
'duration',
'events',
'id',
'instrumentationScope',
'kind',
'links',
'name',
Expand All @@ -95,6 +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 === instrumentationScopeName
);
assert.ok(
firstSpan.instrumentationLibrary.version ===
instrumentationScopeVersion
);

assert.ok(spyExport.calledOnce);
});
Expand Down

0 comments on commit 746ae3b

Please sign in to comment.