Skip to content

Commit 033c64a

Browse files
committed
reduce bundle size
1 parent 0b5dc28 commit 033c64a

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)