Skip to content

Commit

Permalink
fix(sdk-trace-base): ensure attribute value length limit is enforced …
Browse files Browse the repository at this point in the history
…on span creation (#4417)

* fix(sdk-trace-base): ensure attribute value length limit is enforced on span creation

* fix(changelog): add changelog entry
  • Loading branch information
pichlermarc authored Jan 15, 2024
1 parent 5700853 commit 6898a34
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/

### :bug: (Bug Fix)

* fix(sdk-trace-base): ensure attribute value length limit is enforced on span creation [#4417](https://github.com/open-telemetry/opentelemetry-js/pull/4417) @pichlermarc

### :books: (Refine Doc)

### :house: (Internal)
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ export class Span implements APISpan, ReadableSpan {
this.resource = parentTracer.resource;
this.instrumentationLibrary = parentTracer.instrumentationLibrary;
this._spanLimits = parentTracer.getSpanLimits();
this._attributeValueLengthLimit =
this._spanLimits.attributeValueLengthLimit || 0;

if (attributes != null) {
this.setAttributes(attributes);
}

this._spanProcessor = parentTracer.getActiveSpanProcessor();
this._spanProcessor.onStart(this, context);
this._attributeValueLengthLimit =
this._spanLimits.attributeValueLengthLimit || 0;
}

spanContext(): SpanContext {
Expand Down
16 changes: 16 additions & 0 deletions packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,22 @@ describe('Span', () => {
span.setAttribute('attr-non-string', true);
assert.strictEqual(span.attributes['attr-non-string'], true);
});

it('should truncate value when attributes are passed to the constructor', () => {
const span = new Span(
tracer,
ROOT_CONTEXT,
name,
spanContext,
SpanKind.CLIENT,
undefined,
undefined,
undefined,
undefined,
{ 'attr-with-more-length': 'abcdefgh' }
);
assert.strictEqual(span.attributes['attr-with-more-length'], 'abcde');
});
});

describe('when "attributeValueLengthLimit" option is invalid', () => {
Expand Down

0 comments on commit 6898a34

Please sign in to comment.