@@ -73,6 +73,7 @@ export class SentrySpanExporter {
73
73
// Essentially a a set of span ids that are already sent. The values are expiration
74
74
// times in this cache so we don't hold onto them indefinitely.
75
75
private _sentSpans : Map < string , number > ;
76
+ /* Internally, we use a debounced flush to give some wiggle room to the span processor to accumulate more spans. */
76
77
private _debouncedFlush : ReturnType < typeof debounce > ;
77
78
78
79
public constructor ( options ?: {
@@ -87,7 +88,10 @@ export class SentrySpanExporter {
87
88
this . _debouncedFlush = debounce ( this . flush . bind ( this ) , 1 , { maxWait : 100 } ) ;
88
89
}
89
90
90
- /** Export a single span. */
91
+ /**
92
+ * Export a single span.
93
+ * This is called by the span processor whenever a span is ended.
94
+ */
91
95
public export ( span : ReadableSpan ) : void {
92
96
const currentTimestampInS = Math . floor ( Date . now ( ) / 1000 ) ;
93
97
@@ -124,7 +128,11 @@ export class SentrySpanExporter {
124
128
}
125
129
}
126
130
127
- /** Try to flush any pending spans immediately. */
131
+ /**
132
+ * Try to flush any pending spans immediately.
133
+ * This is called internally by the exporter (via _debouncedFlush),
134
+ * but can also be triggered externally if we force-flush.
135
+ */
128
136
public flush ( ) : void {
129
137
const finishedSpans : ReadableSpan [ ] = [ ] ;
130
138
for ( const bucket of this . _finishedSpanBuckets ) {
@@ -155,12 +163,15 @@ export class SentrySpanExporter {
155
163
}
156
164
}
157
165
// Cancel a pending debounced flush, if there is one
158
- // This can be relevant if we directly export , circumventing the debounce
166
+ // This can be relevant if we directly flush , circumventing the debounce
159
167
// in that case, we want to cancel any pending debounced flush
160
168
this . _debouncedFlush . cancel ( ) ;
161
169
}
162
170
163
- /** Clear the exporter. */
171
+ /**
172
+ * Clear the exporter.
173
+ * This is called when the span processor is shut down.
174
+ */
164
175
public clear ( ) : void {
165
176
this . _finishedSpanBuckets = this . _finishedSpanBuckets . fill ( undefined ) ;
166
177
this . _sentSpans . clear ( ) ;
0 commit comments