Repository navigation
feat: retry failed batches with exponential backoff - #34
Merged
Merged
Conversation
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.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## feat/batch-and-flush #34 +/- ##
========================================================
- Coverage 91.42% 91.27% -0.15%
========================================================
Files 3 3
Lines 140 172 +32
========================================================
+ Hits 128 157 +29
- Misses 7 9 +2
- Partials 5 6 +1
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:
|
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.
Wait a random duration between 100% and 150% of the backoff, so the configured RetryBackoff stays a lower bound.
samber
marked this pull request as ready for review
October 13, 2026 15:46
samber
added a commit
that referenced
this pull request
Oct 13, 2026
* 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
samber
added a commit
that referenced
this pull request
Oct 13, 2026
* 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
samber
added a commit
that referenced
this pull request
Oct 13, 2026
* 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
samber
added a commit
that referenced
this pull request
Oct 13, 2026
* feat: batch records and flush them on Close 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 (#34) * 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 * test: rename batch_test.go to dispatcher_test.go Match the file it covers, dispatcher.go. * test: close the handler in the default OnError test
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 #33.
A batch hit by a network error, a 429 or a 5xx was lost on the first failure.
MaxRetries(3,-1disables),RetryBackoff(500ms), the doubling delay is capped at 30s before jitterOnErroronce retries are exhausted