* Add a span to the buffer.
(spanJSON: SerializedStreamedSpanWithSegmentSpan)
| 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. |
no test coverage detected