Skip to content

Commit dcf93e8

Browse files
HyunnoHpichlermarc
andauthored
feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord (#4289)
* feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord * chore: check droppedAttributesCount value in test case * feat(otlp-transformer): make toLogRecord() use ReadableLogRecord.droppedAttributesCount --------- Co-authored-by: Marc Pichler <[email protected]>
1 parent 9e94536 commit dcf93e8

File tree

9 files changed

+17
-2
lines changed

9 files changed

+17
-2
lines changed

experimental/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to experimental packages in this project will be documented
88

99
### :rocket: (Enhancement)
1010

11+
* feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord
12+
1113
### :bug: (Bug Fix)
1214

1315
* fix(sdk-logs): avoid map attribute set when count limit exceeded

experimental/packages/exporter-logs-otlp-grpc/test/logsHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = {
4949
attributes: {
5050
'some-attribute': 'some attribute value',
5151
},
52+
droppedAttributesCount: 0,
5253
severityNumber: SeverityNumber.ERROR,
5354
severityText: 'error',
5455
body: 'some_log_body',

experimental/packages/exporter-logs-otlp-http/test/logHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = {
4444
attributes: {
4545
'some-attribute': 'some attribute value',
4646
},
47+
droppedAttributesCount: 0,
4748
severityNumber: SeverityNumber.ERROR,
4849
severityText: 'error',
4950
body: 'some_log_body',

experimental/packages/exporter-logs-otlp-proto/test/logHelper.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export const mockedReadableLogRecord: ReadableLogRecord = {
4545
attributes: {
4646
'some-attribute': 'some attribute value',
4747
},
48+
droppedAttributesCount: 0,
4849
severityNumber: SeverityNumber.ERROR,
4950
severityText: 'error',
5051
body: 'some_log_body',

experimental/packages/otlp-transformer/src/logs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function toLogRecord(log: ReadableLogRecord, encoder: Encoder): ILogRecord {
101101
severityText: log.severityText,
102102
body: toAnyValue(log.body),
103103
attributes: toLogAttributes(log.attributes),
104-
droppedAttributesCount: 0,
104+
droppedAttributesCount: log.droppedAttributesCount,
105105
flags: log.spanContext?.traceFlags,
106106
traceId: encoder.encodeOptionalSpanContext(log.spanContext?.traceId),
107107
spanId: encoder.encodeOptionalSpanContext(log.spanContext?.spanId),

experimental/packages/otlp-transformer/test/logs.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ describe('Logs', () => {
107107
attributes: {
108108
'some-attribute': 'some attribute value',
109109
},
110+
droppedAttributesCount: 0,
110111
severityNumber: SeverityNumber.ERROR,
111112
severityText: 'error',
112113
body: 'some_log_body',
@@ -122,6 +123,7 @@ describe('Logs', () => {
122123
attributes: {
123124
'another-attribute': 'another attribute value',
124125
},
126+
droppedAttributesCount: 0,
125127
};
126128
log_1_1_1 = {
127129
...log_fragment_1,

experimental/packages/sdk-logs/src/LogRecord.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class LogRecord implements ReadableLogRecord {
3939
private _severityText?: string;
4040
private _severityNumber?: logsAPI.SeverityNumber;
4141
private _body?: string;
42+
private totalAttributesCount: number = 0;
4243

4344
private _isReadonly: boolean = false;
4445
private readonly _logRecordLimits: Required<LogRecordLimits>;
@@ -73,6 +74,10 @@ export class LogRecord implements ReadableLogRecord {
7374
return this._body;
7475
}
7576

77+
get droppedAttributesCount(): number {
78+
return this.totalAttributesCount - Object.keys(this.attributes).length;
79+
}
80+
7681
constructor(
7782
_sharedState: LoggerProviderSharedState,
7883
instrumentationScope: InstrumentationScope,
@@ -129,6 +134,7 @@ export class LogRecord implements ReadableLogRecord {
129134
api.diag.warn(`Invalid attribute value set for key: ${key}`);
130135
return this;
131136
}
137+
this.totalAttributesCount += 1;
132138
if (
133139
Object.keys(this.attributes).length >=
134140
this._logRecordLimits.attributeCountLimit &&

experimental/packages/sdk-logs/src/export/ReadableLogRecord.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export interface ReadableLogRecord {
2929
readonly resource: IResource;
3030
readonly instrumentationScope: InstrumentationScope;
3131
readonly attributes: LogAttributes;
32+
readonly droppedAttributesCount: number;
3233
}

experimental/packages/sdk-logs/test/common/LogRecord.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,14 @@ describe('LogRecord', () => {
203203
}
204204

205205
it('should remove / drop all remaining values after the number of values exceeds this limit', () => {
206-
const { attributes } = logRecord;
206+
const { attributes, droppedAttributesCount } = logRecord;
207207
assert.strictEqual(Object.keys(attributes).length, 100);
208208
assert.strictEqual(attributes.foo0, 'bar0');
209209
assert.deepStrictEqual(attributes.foo98, { bar: 'bar98' });
210210
assert.strictEqual(attributes.foo147, undefined);
211211
assert.strictEqual(attributes.foo148, undefined);
212212
assert.strictEqual(attributes.foo149, undefined);
213+
assert.strictEqual(droppedAttributesCount, 50);
213214
});
214215
});
215216

0 commit comments

Comments
 (0)