Repository navigation
feat: batch records and flush them on Close - #33
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #33 +/- ##
===========================================
+ Coverage 75.90% 92.39% +16.49%
===========================================
Files 2 3 +1
Lines 83 171 +88
===========================================
+ Hits 63 158 +95
+ Misses 16 7 -9
- Partials 4 6 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
samber
force-pushed
the
feat/batch-and-flush
branch
2 times, most recently
from
October 13, 2026 15:55
69a6fda to
bd187f8
Compare
Each record was sent in its own goroutine, so records logged right before the process exited were lost and a log burst opened one request per record. Records now go through a bounded queue to a single worker that sends batches (BatchSize, FlushInterval, QueueSize). Close delivers what is still queued. When the queue is full, records are dropped and reported through OnError, so logging never blocks the caller. NewBetterstackHandler now returns *BetterstackHandler, which still implements slog.Handler.
* feat: retry failed batches with exponential backoff A batch hit by a network error, a 429 or a 5xx was lost on the first failure. Retry those with a doubling delay (MaxRetries, RetryBackoff), capped at 30s per wait. Other 4xx responses and marshaling failures are not retried: they fail the same way every time. The last error is reported through OnError once retries are exhausted. * feat: add jitter to retry backoff Handlers that failed together, for example during a server outage, retried at the same instants. Wait a random duration between 50% and 100% of the backoff. * feat: make retry jitter additive Wait a random duration between 100% and 150% of the backoff, so the configured RetryBackoff stays a lower bound. * docs: clarify that the backoff cap applies before jitter
Match the file it covers, dispatcher.go.
samber
force-pushed
the
feat/batch-and-flush
branch
from
October 13, 2026 15:57
bd187f8 to
5b3c3f4
Compare
samber
marked this pull request as ready for review
October 13, 2026 15:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #32.
Each record was sent in its own goroutine: records logged right before the process exits were lost, and a burst of logs opened one request per record.
BatchSize(100),FlushInterval(1s),QueueSize(1000)Close()delivers the records still queued; idempotent; covers handlers derived withWith/WithGroupOnError, logging never blocksNewBetterstackHandlerreturns*BetterstackHandler(still aslog.Handler)Close