Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
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 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