Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Await for flushInProgress when flushingAll #3

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
private _timer: NodeJS.Timeout | undefined;
private _shutdownOnce: BindOnceFuture<void>;
private _droppedSpansCount: number = 0;
private _isFlushInProgress: boolean = false;
private _flushInProgress: Promise<void> | null = null;
RafalSumislawski marked this conversation as resolved.
Show resolved Hide resolved

constructor(private readonly _exporter: SpanExporter, config?: T) {
const env = getEnv();
Expand Down Expand Up @@ -162,6 +162,9 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
// run exports in parallel ignoring _isFlushInProgress
promises.push(this._export(spans));
}
if (this._flushInProgress) {
promises.push(this._flushInProgress);
}
Promise.all(promises)
.then(() => {
resolve();
Expand Down Expand Up @@ -230,24 +233,23 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig>
}

private _flush() {
if (this._isFlushInProgress) {
if (this._flushInProgress) {
return;
}
this._isFlushInProgress = true;
this._clearTimer();

const spans = this._finishedSpans.splice(0, this._maxExportBatchSize);
this._export(spans)
this._flushInProgress = this._export(spans);
this._flushInProgress
.then(() => {
this._isFlushInProgress = false;
this._flushInProgress = null;
if (this._finishedSpans.length >= this._maxExportBatchSize) {
this._flush();
} else if (this._finishedSpans.length > 0) {
this._maybeStartTimer();
}
})
.catch(e => {
this._isFlushInProgress = false;
this._flushInProgress = null;
globalErrorHandler(e);
if (this._finishedSpans.length >= this._maxExportBatchSize) {
this._flush();
Expand Down
Loading