Skip to content

Commit c6e9af2

Browse files
committed
add more comments to clarify things
1 parent 004de6f commit c6e9af2

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/opentelemetry/src/spanExporter.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export class SentrySpanExporter {
7373
// Essentially a a set of span ids that are already sent. The values are expiration
7474
// times in this cache so we don't hold onto them indefinitely.
7575
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. */
7677
private _debouncedFlush: ReturnType<typeof debounce>;
7778

7879
public constructor(options?: {
@@ -87,7 +88,10 @@ export class SentrySpanExporter {
8788
this._debouncedFlush = debounce(this.flush.bind(this), 1, { maxWait: 100 });
8889
}
8990

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+
*/
9195
public export(span: ReadableSpan): void {
9296
const currentTimestampInS = Math.floor(Date.now() / 1000);
9397

@@ -124,7 +128,11 @@ export class SentrySpanExporter {
124128
}
125129
}
126130

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+
*/
128136
public flush(): void {
129137
const finishedSpans: ReadableSpan[] = [];
130138
for (const bucket of this._finishedSpanBuckets) {
@@ -155,12 +163,15 @@ export class SentrySpanExporter {
155163
}
156164
}
157165
// 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
159167
// in that case, we want to cancel any pending debounced flush
160168
this._debouncedFlush.cancel();
161169
}
162170

163-
/** Clear the exporter. */
171+
/**
172+
* Clear the exporter.
173+
* This is called when the span processor is shut down.
174+
*/
164175
public clear(): void {
165176
this._finishedSpanBuckets = this._finishedSpanBuckets.fill(undefined);
166177
this._sentSpans.clear();

0 commit comments

Comments
 (0)