diff --git a/packages/opentelemetry-sdk-trace-base/src/Span.ts b/packages/opentelemetry-sdk-trace-base/src/Span.ts index c4bd66b20c..79ceae7ffc 100644 --- a/packages/opentelemetry-sdk-trace-base/src/Span.ts +++ b/packages/opentelemetry-sdk-trace-base/src/Span.ts @@ -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(); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts index d9ca0b1301..e29276b630 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/Span.test.ts @@ -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,