diff --git a/CHANGELOG.md b/CHANGELOG.md index f1670b19c7..9a2a00a259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ * feat(sdk-metrics): apply binary search in histogram recording [#3539](https://github.com/open-telemetry/opentelemetry-js/pull/3539) @legendecas * perf(propagator-jaeger): improve deserializeSpanContext performance [#3541](https://github.com/open-telemetry/opentelemetry-js/pull/3541) @doochik * feat: support TraceState in SamplingResult [#3530](https://github.com/open-telemetry/opentelemetry-js/pull/3530) @raphael-theriault-swi +* feat(sdk-trace-base): add diagnostic logging when spans are dropped [#3610](https://github.com/open-telemetry/opentelemetry-js/pull/3610) @neoeinstein ### :bug: (Bug Fix) diff --git a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts index 1a0968642d..42c7ac4965 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts @@ -44,6 +44,7 @@ export abstract class BatchSpanProcessorBase private _finishedSpans: ReadableSpan[] = []; private _timer: NodeJS.Timeout | undefined; private _shutdownOnce: BindOnceFuture; + private _droppedSpansCount: number = 0; constructor(private readonly _exporter: SpanExporter, config?: T) { const env = getEnv(); @@ -117,8 +118,23 @@ export abstract class BatchSpanProcessorBase private _addToBuffer(span: ReadableSpan) { if (this._finishedSpans.length >= this._maxQueueSize) { // limit reached, drop span + + if (this._droppedSpansCount === 0) { + diag.debug('maxQueueSize reached, dropping spans'); + } + this._droppedSpansCount++; + return; } + + if (this._droppedSpansCount > 0) { + // some spans were dropped, log once with count of spans dropped + diag.warn( + `Dropped ${this._droppedSpansCount} spans because maxQueueSize reached` + ); + this._droppedSpansCount = 0; + } + this._finishedSpans.push(span); this._maybeStartTimer(); }