-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(sdk-logs)!: implement scope attributes for logger creation #6573
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
aa76b8c
ae66341
c9cf015
318178a
f435d88
76c9d3c
98b6f26
ec46c6b
e814dcc
0529248
6401e7a
51fea11
858d1e1
11af96c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,11 +16,9 @@ import { | |
| createInstrumentationScope, | ||
| createResource, | ||
| toAnyValue, | ||
| toKeyValue, | ||
| toAttributes, | ||
| } from '../common/internal'; | ||
| import type { SeverityNumber } from '@opentelemetry/api-logs'; | ||
| import type { IKeyValue } from '../common/internal-types'; | ||
| import type { LogAttributes } from '@opentelemetry/api-logs'; | ||
|
|
||
| export function createExportLogsServiceRequest( | ||
| logRecords: ReadableLogRecord[], | ||
|
|
@@ -33,29 +31,28 @@ export function createExportLogsServiceRequest( | |
|
|
||
| function createResourceMap( | ||
| logRecords: ReadableLogRecord[] | ||
| ): Map<Resource, Map<string, ReadableLogRecord[]>> { | ||
| ): Map< | ||
| Resource, | ||
| Map<ReadableLogRecord['instrumentationScope'], ReadableLogRecord[]> | ||
| > { | ||
| const resourceMap: Map< | ||
| Resource, | ||
| Map<string, ReadableLogRecord[]> | ||
| Map<ReadableLogRecord['instrumentationScope'], ReadableLogRecord[]> | ||
| > = new Map(); | ||
|
|
||
| for (const record of logRecords) { | ||
| const { | ||
| resource, | ||
| instrumentationScope: { name, version = '', schemaUrl = '' }, | ||
| } = record; | ||
| const { resource, instrumentationScope } = record; | ||
|
|
||
| let ismMap = resourceMap.get(resource); | ||
| if (!ismMap) { | ||
| ismMap = new Map(); | ||
| resourceMap.set(resource, ismMap); | ||
| } | ||
|
|
||
| const ismKey = `${name}@${version}:${schemaUrl}`; | ||
| let records = ismMap.get(ismKey); | ||
| let records = ismMap.get(instrumentationScope); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note for reviewers: by avoding this string operation we get a significant performance boost for JSON serialization. we already do this in the protobuf serializer for performance reasons. Having to the string operation for each log record with scopeAttributes would be quite expensive. Old: New: |
||
| if (!records) { | ||
| records = []; | ||
| ismMap.set(ismKey, records); | ||
| ismMap.set(instrumentationScope, records); | ||
| } | ||
| records.push(record); | ||
| } | ||
|
|
@@ -73,7 +70,10 @@ function logRecordsToResourceLogs( | |
| resource: processedResource, | ||
| scopeLogs: Array.from(ismMap, ([, scopeLogs]) => { | ||
| return { | ||
| scope: createInstrumentationScope(scopeLogs[0].instrumentationScope), | ||
| scope: createInstrumentationScope( | ||
| scopeLogs[0].instrumentationScope, | ||
| encoder | ||
| ), | ||
| logRecords: scopeLogs.map(log => toLogRecord(log, encoder)), | ||
| schemaUrl: scopeLogs[0].instrumentationScope.schemaUrl, | ||
| }; | ||
|
|
@@ -91,7 +91,7 @@ function toLogRecord(log: ReadableLogRecord, encoder: Encoder): ILogRecord { | |
| severityText: log.severityText, | ||
| body: toAnyValue(log.body, encoder), | ||
| eventName: log.eventName, | ||
| attributes: toLogAttributes(log.attributes, encoder), | ||
| attributes: toAttributes(log.attributes, encoder), | ||
| droppedAttributesCount: log.droppedAttributesCount, | ||
| flags: log.spanContext?.traceFlags, | ||
| traceId: encoder.encodeOptionalSpanContext(log.spanContext?.traceId), | ||
|
|
@@ -104,12 +104,3 @@ function toSeverityNumber( | |
| ): ESeverityNumber | undefined { | ||
| return severityNumber as number | undefined as ESeverityNumber | undefined; | ||
| } | ||
|
|
||
| export function toLogAttributes( | ||
| attributes: LogAttributes, | ||
| encoder: Encoder | ||
| ): IKeyValue[] { | ||
| return Object.keys(attributes).map(key => | ||
| toKeyValue(key, attributes[key], encoder) | ||
| ); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.