Skip to content

Commit

Permalink
fix: span evets count limit when set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Bataran committed Dec 21, 2021
1 parent 2c8601f commit 6936ea6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/opentelemetry-sdk-trace-base/src/Span.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ export class Span implements api.Span, ReadableSpan {
startTime?: api.TimeInput
): this {
if (this._isSpanEnded()) return this;
if (this._spanLimits.eventCountLimit === 0) {
api.diag.warn('No events allowed.');
return this;
}
if (this.events.length >= this._spanLimits.eventCountLimit!) {
api.diag.warn('Dropping extra events.');
this.events.shift();
Expand Down
22 changes: 22 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 @@ -621,6 +621,28 @@ describe('Span', () => {
assert.strictEqual(span.events[span.events.length - 1].name, 'sent149');
});

it('should add no event', () => {
const tracer = new BasicTracerProvider({
spanLimits: {
eventCountLimit: 0,
},
}).getTracer('default');

const span = new Span(
tracer,
ROOT_CONTEXT,
name,
spanContext,
SpanKind.CLIENT
);
for (let i = 0; i < 10; i++) {
span.addEvent('sent' + i);
}
span.end();

assert.strictEqual(span.events.length, 0);
});

it('should set an error status', () => {
const span = new Span(
tracer,
Expand Down

0 comments on commit 6936ea6

Please sign in to comment.