File tree Expand file tree Collapse file tree
packages/core/src/tracing/spans Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ;
You can’t perform that action at this time.
0 commit comments