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

Method flush

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

* Flush spans of a specific trace. * In contrast to SpanBuffer.drain, this method does not flush all traces, but only the one with the given traceId.

(traceId: string)

Source from the content-addressed store, hash-verified

145 * In contrast to {@link SpanBuffer.drain}, this method does not flush all traces, but only the one with the given traceId.
146 */
147 public flush(traceId: string): void {
148 const bucket = this._traceBuckets.get(traceId);
149 if (!bucket) {
150 return;
151 }
152
153 if (!bucket.spans.size) {
154 // we should never get here, given we always add a span when we create a new bucket
155 // and delete the bucket once we flush out the trace
156 this._removeTrace(traceId);
157 return;
158 }
159
160 const spans = Array.from(bucket.spans);
161
162 const segmentSpan = spans[0]?._segmentSpan;
163 if (!segmentSpan) {
164 DEBUG_BUILD && debug.warn('No segment span reference found on span JSON, cannot compute DSC');
165 this._removeTrace(traceId);
166 return;
167 }
168
169 const dsc = getDynamicSamplingContextFromSpan(segmentSpan);
170
171 const cleanedSpans: SerializedStreamedSpan[] = spans.map(spanJSON => {
172 // eslint-disable-next-line @typescript-eslint/no-unused-vars
173 const { _segmentSpan, ...cleanSpanJSON } = spanJSON;
174 return cleanSpanJSON;
175 });
176
177 const envelope = createStreamedSpanEnvelope(cleanedSpans, dsc, this._client);
178
179 DEBUG_BUILD && debug.log(`Sending span envelope for trace ${traceId} with ${cleanedSpans.length} spans`);
180
181 this._client.sendEnvelope(envelope).then(null, reason => {
182 DEBUG_BUILD && debug.error('Error while sending streamed span envelope:', reason);
183 });
184
185 this._removeTrace(traceId);
186 }
187
188 private _removeTrace(traceId: string): void {
189 const bucket = this._traceBuckets.get(traceId);

Callers 3

setupFunction · 0.95
addMethod · 0.95
drainMethod · 0.95

Calls 9

_removeTraceMethod · 0.95
getMethod · 0.65
warnMethod · 0.65
logMethod · 0.65
errorMethod · 0.65
fromMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected