From 12a13f1fb0f7c24c85cec5416d35e6da7e191e39 Mon Sep 17 00:00:00 2001 From: Hyun Oh Date: Sat, 11 Nov 2023 00:59:39 +0900 Subject: [PATCH 1/3] 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 bb1fd6aca06..6b23c286ba3 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 633d1a7833a..21e151d2277 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 bc4d17a4f0f..11facc4402e 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 ae72deae335..ab2f0885033 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 85e55e9fd76..18dfbdabe4e 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 8d8fae6168d..d827c7fa1dd 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 a7eff21e2dc..2dc3ece8658 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; } From c236f70c9c559d72f3c65c831563c9e15944fbc9 Mon Sep 17 00:00:00 2001 From: Hyun Oh Date: Sat, 11 Nov 2023 09:54:48 +0900 Subject: [PATCH 2/3] chore: check droppedAttributesCount value in test case --- experimental/packages/sdk-logs/test/common/LogRecord.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/experimental/packages/sdk-logs/test/common/LogRecord.test.ts b/experimental/packages/sdk-logs/test/common/LogRecord.test.ts index 678b4c2e726..5a0acaa6db2 100644 --- a/experimental/packages/sdk-logs/test/common/LogRecord.test.ts +++ b/experimental/packages/sdk-logs/test/common/LogRecord.test.ts @@ -203,13 +203,14 @@ describe('LogRecord', () => { } it('should remove / drop all remaining values after the number of values exceeds this limit', () => { - const { attributes } = logRecord; + const { attributes, droppedAttributesCount } = logRecord; assert.strictEqual(Object.keys(attributes).length, 100); assert.strictEqual(attributes.foo0, 'bar0'); assert.deepStrictEqual(attributes.foo98, { bar: 'bar98' }); assert.strictEqual(attributes.foo147, undefined); assert.strictEqual(attributes.foo148, undefined); assert.strictEqual(attributes.foo149, undefined); + assert.strictEqual(droppedAttributesCount, 50); }); }); From 331f78d6e2cd6bff49041062665b721cbff534e7 Mon Sep 17 00:00:00 2001 From: HyunnoH Date: Tue, 14 Nov 2023 13:19:58 +0900 Subject: [PATCH 3/3] feat(otlp-transformer): make toLogRecord() use ReadableLogRecord.droppedAttributesCount --- experimental/packages/otlp-transformer/src/logs/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/experimental/packages/otlp-transformer/src/logs/index.ts b/experimental/packages/otlp-transformer/src/logs/index.ts index 9ca1a40c282..b690484a71c 100644 --- a/experimental/packages/otlp-transformer/src/logs/index.ts +++ b/experimental/packages/otlp-transformer/src/logs/index.ts @@ -101,7 +101,7 @@ function toLogRecord(log: ReadableLogRecord, encoder: Encoder): ILogRecord { severityText: log.severityText, body: toAnyValue(log.body), attributes: toLogAttributes(log.attributes), - droppedAttributesCount: 0, + droppedAttributesCount: log.droppedAttributesCount, flags: log.spanContext?.traceFlags, traceId: encoder.encodeOptionalSpanContext(log.spanContext?.traceId), spanId: encoder.encodeOptionalSpanContext(log.spanContext?.spanId),