Skip to content

Commit

Permalink
Merge f177746 into d434f84
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunnoH authored Nov 6, 2023
2 parents d434f84 + f177746 commit 27c4172
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to experimental packages in this project will be documented
* fix(sdk-node): remove the explicit dependency on @opentelemetry/exporter-jaeger that was kept on the previous release
* '@opentelemetry/exporter-jaeger' is no longer be a dependency of this package. To continue using '@opentelemetry/exporter-jaeger', please install it manually.
* NOTE: `@opentelemetry/exporter-jaeger` is deprecated, consider switching to one of the alternatives described [here](https://www.npmjs.com/package/@opentelemetry/exporter-jaeger)
* fix(sdk-logs): avoid map attribute set when count limit exceeded
* fix(otlp-transformer): OTLP json encoding [#4220](https://github.com/open-telemetry/opentelemetry-js/pull/4220) @seemk
* Fixes a bug in the OTLP (http/json) exporters where timestamps were not encoded as strings, causing the export to
be rejected by OTLP endpoints
Expand Down
22 changes: 13 additions & 9 deletions experimental/packages/sdk-logs/src/LogRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,18 @@ export class LogRecord implements ReadableLogRecord {
if (value === null) {
return this;
}
if (
typeof value === 'object' &&
!Array.isArray(value) &&
Object.keys(value).length > 0
) {
this.attributes[key] = value;
}
if (key.length === 0) {
api.diag.warn(`Invalid attribute key: ${key}`);
return this;
}
if (!isAttributeValue(value)) {
if (
!isAttributeValue(value) &&
!(
typeof value === 'object' &&
!Array.isArray(value) &&
Object.keys(value).length > 0
)
) {
api.diag.warn(`Invalid attribute value set for key: ${key}`);
return this;
}
Expand All @@ -136,7 +136,11 @@ export class LogRecord implements ReadableLogRecord {
) {
return this;
}
this.attributes[key] = this._truncateToSize(value);
if (isAttributeValue(value)) {
this.attributes[key] = this._truncateToSize(value);
} else {
this.attributes[key] = value;
}
return this;
}

Expand Down
24 changes: 22 additions & 2 deletions experimental/packages/sdk-logs/test/common/LogRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,34 @@ describe('LogRecord', () => {
describe('when "attributeCountLimit" option defined', () => {
const { logRecord } = setup({ attributeCountLimit: 100 });
for (let i = 0; i < 150; i++) {
logRecord.setAttribute(`foo${i}`, `bar${i}`);
let attributeValue;
switch (i % 3) {
case 0: {
attributeValue = `bar${i}`;
break;
}
case 1: {
attributeValue = [`bar${i}`];
break;
}
case 2: {
attributeValue = {
bar: `bar${i}`,
};
break;
}
default: {
attributeValue = `bar${i}`;
}
}
logRecord.setAttribute(`foo${i}`, attributeValue);
}

it('should remove / drop all remaining values after the number of values exceeds this limit', () => {
const { attributes } = logRecord;
assert.strictEqual(Object.keys(attributes).length, 100);
assert.strictEqual(attributes.foo0, 'bar0');
assert.strictEqual(attributes.foo99, 'bar99');
assert.deepStrictEqual(attributes.foo98, { bar: 'bar98' });
assert.strictEqual(attributes.foo149, undefined);
});
});
Expand Down

0 comments on commit 27c4172

Please sign in to comment.