Skip to content

Commit 2cdf920

Browse files
committed
listen to 'close'
1 parent 471048d commit 2cdf920

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/core/src/tracing/spans/spanBuffer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ export class SpanBuffer {
6969
this._client.on('flush', () => {
7070
this.drain();
7171
});
72+
73+
this._client.on('close', () => {
74+
// No need to drain the buffer here as `Client.close()` internally already calls `Client.flush()`
75+
// which already invokes the `flush` hook and thus drains the buffer.
76+
if (this._flushIntervalId) {
77+
clearInterval(this._flushIntervalId);
78+
}
79+
this._traceMap.clear();
80+
});
7281
}
7382

7483
/**
@@ -134,7 +143,7 @@ export class SpanBuffer {
134143

135144
const dsc = getDynamicSamplingContextFromSpan(segmentSpan);
136145

137-
const cleanedSpans: SerializedStreamedSpan[] = Array.from(traceBucket).map(spanJSON => {
146+
const cleanedSpans: SerializedStreamedSpan[] = spans.map(spanJSON => {
138147
// eslint-disable-next-line @typescript-eslint/no-unused-vars
139148
const { _segmentSpan, ...cleanSpanJSON } = spanJSON;
140149
return cleanSpanJSON;

0 commit comments

Comments
 (0)