MCPcopy Create free account
hub / github.com/getsentry/sentry-javascript / add

Method add

packages/core/src/tracing/spans/spanBuffer.ts:103–126  ·  view source on GitHub ↗

* Add a span to the buffer.

(spanJSON: SerializedStreamedSpanWithSegmentSpan)

Source from the content-addressed store, hash-verified

101 * Add a span to the buffer.
102 */
103 public add(spanJSON: SerializedStreamedSpanWithSegmentSpan): void {
104 const traceId = spanJSON.trace_id;
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);
125 }
126 }
127
128 /**
129 * Drain and flush all buffered traces.

Callers 2

setupFunction · 0.95
setupFunction · 0.95

Calls 7

flushMethod · 0.95
safeUnrefFunction · 0.90
setTimeoutFunction · 0.85
getMethod · 0.65
setMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected