diff --git a/src/batcher.js b/src/batcher.js index af50c40..60b1a7f 100644 --- a/src/batcher.js +++ b/src/batcher.js @@ -253,15 +253,21 @@ class Batcher { } } + const savedBatchStreams = this.batch.streams + + // No need to clear the batch if batching is disabled + logEntry === undefined && this.clearBatch() + // Send the data to Grafana Loki req.post(this.url, this.contentType, this.options.headers, reqBody, this.options.timeout, this.options.httpAgent, this.options.httpsAgent) .then(() => { - // No need to clear the batch if batching is disabled - logEntry === undefined && this.clearBatch() this.batchSent() resolve() }) .catch(err => { + // Revert batch for the logs to be sent on the next iteration + this.batch.streams = savedBatchStreams + // Clear the batch on error if enabled this.options.clearOnError && this.clearBatch()