Skip to content

Commit

Permalink
perf(export): do not use splice if fit in one batch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ievgen Makukh committed Mar 17, 2024
1 parent c5b52e2 commit c30f8ff
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ import { SpanExporter } from './SpanExporter';
* the SDK then pushes them to the exporter pipeline.
*/
export abstract class BatchSpanProcessorBase<T extends BufferConfig>
implements SpanProcessor
{
implements SpanProcessor {
private readonly _maxExportBatchSize: number;
private readonly _maxQueueSize: number;
private readonly _scheduledDelayMillis: number;
Expand Down Expand Up @@ -87,7 +86,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
}

// does nothing.
onStart(_span: Span, _parentContext: Context): void {}
onStart(_span: Span, _parentContext: Context): void { }

onEnd(span: ReadableSpan): void {
if (this._shutdownOnce.isCalled) {
Expand Down Expand Up @@ -181,7 +180,14 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
// 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 => {
Expand All @@ -191,7 +197,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
} else {
reject(
result.error ??
new Error('BatchSpanProcessor: span export failed')
new Error('BatchSpanProcessor: span export failed')
);
}
});
Expand Down

0 comments on commit c30f8ff

Please sign in to comment.