Skip to content

Commit e7d0695

Browse files
committed
chore: do not flush empty batch span processor
1 parent 755ce9c commit e7d0695

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/opentelemetry-tracing/src/export/BatchSpanProcessor.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class BatchSpanProcessor implements SpanProcessor {
4545
: DEFAULT_BUFFER_TIMEOUT_MS;
4646

4747
this._timer = setInterval(() => {
48-
if (Date.now() - this._lastSpanFlush >= this._bufferTimeout) {
48+
if (this._shouldFlush()) {
4949
this._flush();
5050
}
5151
}, this._bufferTimeout);
@@ -73,6 +73,13 @@ export class BatchSpanProcessor implements SpanProcessor {
7373
}
7474
}
7575

76+
private _shouldFlush(): boolean {
77+
return (
78+
this._finishedSpans.length >= 0 &&
79+
Date.now() - this._lastSpanFlush >= this._bufferTimeout
80+
);
81+
}
82+
7683
/** Send the span data list to exporter */
7784
private _flush() {
7885
this._exporter.export(this._finishedSpans, () => {});

0 commit comments

Comments
 (0)