Skip to content

Commit

Permalink
Allow BatchSpanProcessor to send early when a full batch is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSumislawski committed Sep 25, 2023
1 parent 2c9d613 commit b05ebf7
Showing 1 changed file with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,11 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
}

this._finishedSpans.push(span);
this._maybeStartTimer();
if (this._finishedSpans.length == this._maxExportBatchSize) {
this._flushOneBatchAndContinue()
} else {
this._maybeStartTimer();
}
}

/**
Expand Down Expand Up @@ -215,16 +219,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
private _maybeStartTimer() {
if (this._timer !== undefined) return;
this._timer = setTimeout(() => {
this._flushOneBatch()
.then(() => {
if (this._finishedSpans.length > 0) {
this._clearTimer();
this._maybeStartTimer();
}
})
.catch(e => {
globalErrorHandler(e);
});
this._flushOneBatchAndContinue()
}, this._scheduledDelayMillis);
unrefTimer(this._timer);
}
Expand All @@ -236,5 +231,26 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
}
}

private _flushOneBatchAndContinue() {
this._flushOneBatch()
.then(() => {
if (this._finishedSpans.length >= this._maxExportBatchSize) {
this._flushOneBatchAndContinue()
} else if (this._finishedSpans.length > 0) {
this._clearTimer();
this._maybeStartTimer();
}
})
.catch(e => {
globalErrorHandler(e);
if (this._finishedSpans.length >= this._maxExportBatchSize) {
this._flushOneBatchAndContinue()
} else if (this._finishedSpans.length > 0) {
this._clearTimer();
this._maybeStartTimer();
}
});
}

protected abstract onShutdown(): void;
}

0 comments on commit b05ebf7

Please sign in to comment.