From 12a13f1fb0f7c24c85cec5416d35e6da7e191e39 Mon Sep 17 00:00:00 2001 From: Hyun Oh Date: Sat, 11 Nov 2023 00:59:39 +0900 Subject: [PATCH] feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord --- experimental/CHANGELOG.md | 2 ++ .../packages/exporter-logs-otlp-grpc/test/logsHelper.ts | 1 + .../packages/exporter-logs-otlp-http/test/logHelper.ts | 1 + .../packages/exporter-logs-otlp-proto/test/logHelper.ts | 1 + experimental/packages/otlp-transformer/test/logs.test.ts | 2 ++ experimental/packages/sdk-logs/src/LogRecord.ts | 6 ++++++ .../packages/sdk-logs/src/export/ReadableLogRecord.ts | 1 + 7 files changed, 14 insertions(+) diff --git a/experimental/CHANGELOG.md b/experimental/CHANGELOG.md index bb1fd6aca0..6b23c286ba 100644 --- a/experimental/CHANGELOG.md +++ b/experimental/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to experimental packages in this project will be documented ### :rocket: (Enhancement) +* feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord + ### :bug: (Bug Fix) * fix(sdk-logs): avoid map attribute set when count limit exceeded diff --git a/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts b/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts index 633d1a7833..21e151d227 100644 --- a/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts +++ b/experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts @@ -49,6 +49,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = { attributes: { 'some-attribute': 'some attribute value', }, + droppedAttributesCount: 0, severityNumber: SeverityNumber.ERROR, severityText: 'error', body: 'some_log_body', diff --git a/experimental/packages/exporter-logs-otlp-http/test/logHelper.ts b/experimental/packages/exporter-logs-otlp-http/test/logHelper.ts index bc4d17a4f0..11facc4402 100644 --- a/experimental/packages/exporter-logs-otlp-http/test/logHelper.ts +++ b/experimental/packages/exporter-logs-otlp-http/test/logHelper.ts @@ -44,6 +44,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = { attributes: { 'some-attribute': 'some attribute value', }, + droppedAttributesCount: 0, severityNumber: SeverityNumber.ERROR, severityText: 'error', body: 'some_log_body', diff --git a/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts b/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts index ae72deae33..ab2f088503 100644 --- a/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts +++ b/experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts @@ -45,6 +45,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = { attributes: { 'some-attribute': 'some attribute value', }, + droppedAttributesCount: 0, severityNumber: SeverityNumber.ERROR, severityText: 'error', body: 'some_log_body', diff --git a/experimental/packages/otlp-transformer/test/logs.test.ts b/experimental/packages/otlp-transformer/test/logs.test.ts index 85e55e9fd7..18dfbdabe4 100644 --- a/experimental/packages/otlp-transformer/test/logs.test.ts +++ b/experimental/packages/otlp-transformer/test/logs.test.ts @@ -107,6 +107,7 @@ describe('Logs', () => { attributes: { 'some-attribute': 'some attribute value', }, + droppedAttributesCount: 0, severityNumber: SeverityNumber.ERROR, severityText: 'error', body: 'some_log_body', @@ -122,6 +123,7 @@ describe('Logs', () => { attributes: { 'another-attribute': 'another attribute value', }, + droppedAttributesCount: 0, }; log_1_1_1 = { ...log_fragment_1, diff --git a/experimental/packages/sdk-logs/src/LogRecord.ts b/experimental/packages/sdk-logs/src/LogRecord.ts index 8d8fae6168..d827c7fa1d 100644 --- a/experimental/packages/sdk-logs/src/LogRecord.ts +++ b/experimental/packages/sdk-logs/src/LogRecord.ts @@ -39,6 +39,7 @@ export class LogRecord implements ReadableLogRecord { private _severityText?: string; private _severityNumber?: logsAPI.SeverityNumber; private _body?: string; + private totalAttributesCount: number = 0; private _isReadonly: boolean = false; private readonly _logRecordLimits: Required; @@ -73,6 +74,10 @@ export class LogRecord implements ReadableLogRecord { return this._body; } + get droppedAttributesCount(): number { + return this.totalAttributesCount - Object.keys(this.attributes).length; + } + constructor( _sharedState: LoggerProviderSharedState, instrumentationScope: InstrumentationScope, @@ -129,6 +134,7 @@ export class LogRecord implements ReadableLogRecord { api.diag.warn(`Invalid attribute value set for key: ${key}`); return this; } + this.totalAttributesCount += 1; if ( Object.keys(this.attributes).length >= this._logRecordLimits.attributeCountLimit && diff --git a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts index a7eff21e2d..2dc3ece865 100644 --- a/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts +++ b/experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts @@ -29,4 +29,5 @@ export interface ReadableLogRecord { readonly resource: IResource; readonly instrumentationScope: InstrumentationScope; readonly attributes: LogAttributes; + readonly droppedAttributesCount: number; }