File tree Expand file tree Collapse file tree 1 file changed +20
-21
lines changed
packages/core/src/tracing/spans Expand file tree Collapse file tree 1 file changed +20
-21
lines changed Original file line number Diff line number Diff line change @@ -102,27 +102,26 @@ export class SpanBuffer {
102102 */
103103 public add ( spanJSON : SerializedStreamedSpanWithSegmentSpan ) : void {
104104 const traceId = spanJSON . trace_id ;
105- const existingBucket = this . _traceBuckets . get ( traceId ) ;
106-
107- if ( existingBucket ) {
108- existingBucket . spans . add ( spanJSON ) ;
109- existingBucket . size += estimateSerializedSpanSizeInBytes ( spanJSON ) ;
110-
111- if ( existingBucket . spans . size >= this . _maxSpanLimit || existingBucket . size >= this . _maxTraceWeight ) {
112- this . flush ( traceId ) ;
113- }
114- } else {
115- const size = estimateSerializedSpanSizeInBytes ( spanJSON ) ;
116- const timeout = safeUnref (
117- setTimeout ( ( ) => {
118- this . flush ( traceId ) ;
119- } , this . _flushInterval ) ,
120- ) ;
121- this . _traceBuckets . set ( traceId , { spans : new Set ( [ spanJSON ] ) , size, timeout } ) ;
122-
123- if ( size >= this . _maxTraceWeight ) {
124- this . flush ( traceId ) ;
125- }
105+ let bucket = this . _traceBuckets . get ( traceId ) ;
106+
107+ if ( ! bucket ) {
108+ bucket = {
109+ spans : new Set ( ) ,
110+ size : 0 ,
111+ timeout : safeUnref (
112+ setTimeout ( ( ) => {
113+ this . flush ( traceId ) ;
114+ } , this . _flushInterval ) ,
115+ ) ,
116+ } ;
117+ this . _traceBuckets . set ( traceId , bucket ) ;
118+ }
119+
120+ bucket . spans . add ( spanJSON ) ;
121+ bucket . size += estimateSerializedSpanSizeInBytes ( spanJSON ) ;
122+
123+ if ( bucket . spans . size >= this . _maxSpanLimit || bucket . size >= this . _maxTraceWeight ) {
124+ this . flush ( traceId ) ;
126125 }
127126 }
128127
You can’t perform that action at this time.
0 commit comments