Skip to content

Commit

Permalink
feat(sdk-logs): add droppedAttributesCount field to ReadableLogRecord
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunnoH committed Nov 10, 2023
1 parent f5ef8de commit 12a13f1
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
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: 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;
}

0 comments on commit 12a13f1

Please sign in to comment.