From 9daef9526824a2736a876b868c306606e9621a59 Mon Sep 17 00:00:00 2001 From: Samuron Date: Sun, 17 Mar 2024 13:58:59 +0200 Subject: [PATCH] perf(export): do not use splice if fit in one batch --- .../src/export/BatchSpanProcessorBase.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts index 776b7bea212..19e616dc081 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts @@ -181,7 +181,13 @@ export abstract class BatchSpanProcessorBase // Reset the finished spans buffer here because the next invocations of the _flush method // could pass the same finished spans to the exporter if the buffer is cleared // outside the execution of this callback. - const spans = this._finishedSpans.splice(0, this._maxExportBatchSize); + let spans: ReadableSpan[]; + if (this._finishedSpans.length <= this._maxExportBatchSize) { + spans = this._finishedSpans; + this._finishedSpans = []; + } else { + spans = this._finishedSpans.splice(0, this._maxExportBatchSize); + } const doExport = () => this._exporter.export(spans, result => {