Skip to content
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 experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion experimental/packages/otlp-transformer/src/logs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions experimental/packages/otlp-transformer/test/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('Logs', () => {
attributes: {
'some-attribute': 'some attribute value',
},
droppedAttributesCount: 0,
severityNumber: SeverityNumber.ERROR,
severityText: 'error',
body: 'some_log_body',
Expand All @@ -122,6 +123,7 @@ describe('Logs', () => {
attributes: {
'another-attribute': 'another attribute value',
},
droppedAttributesCount: 0,
};
log_1_1_1 = {
...log_fragment_1,
Expand Down
6 changes: 6 additions & 0 deletions experimental/packages/sdk-logs/src/LogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<LogRecordLimits>;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export interface ReadableLogRecord {
readonly resource: IResource;
readonly instrumentationScope: InstrumentationScope;
readonly attributes: LogAttributes;
readonly droppedAttributesCount: number;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand Down