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: include instrumentation scope info in console span and log record exporters #4848

Merged
merged 6 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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