diff --git a/src/ingest/batch.ts b/src/ingest/batch.ts
index 1f4a2e3..a98bc55 100644
--- a/src/ingest/batch.ts
+++ b/src/ingest/batch.ts
@@ -42,12 +42,18 @@ export class BatchProcessor {
private async flush(spans: Span[]): Promise<void> {
const exporter = this.exporters[this.activeIdx];
- const payload = serialize(spans);
- await exporter.send(payload);
- this.buffer.length = 0;
+ if (!exporter) {
+ this.log.warn('no active exporter; dropping batch');
+ return;
+ }
+ const clamped = spans.slice(0, MAX_BATCH_SPANS);
+ const payload = serialize(clamped);
+ await this.sendWithRetry(exporter, payload);
+ this.buffer.length = 0;
}
+ private async sendWithRetry(
+ exporter: SpanExporter,
+ payload: Uint8Array,
+ ): Promise<void> {
+ for (let attempt = 0; attempt < 3; attempt++) {
+ try { await exporter.send(payload); return; }
+ catch (err) { await sleep(150 * (attempt + 1)); }
+ }
+ }