Rate-limit AutoCollectExceptions and drop per-exception forceFlush#1499
Merged
JacksonWeber merged 3 commits intoMay 21, 2026
Merged
Conversation
AutoCollectExceptions previously invoked LoggerProvider.forceFlush() on every uncaughtException and unhandledRejection, with no client-side rate limit. Under exception storms this bypassed BatchLogRecordProcessor batching and amplified request rate against the ingestion endpoint. Changes: - Remove per-exception forceFlush; flush only on the terminal exit path (sole listener + reThrow). - Add a 50/min token-bucket rate limiter; emit a single summary trackException on bucket refill reporting the suppressed count. - Always record the terminal/fatal exception, bypassing the rate limit. - Harden terminal flush with onRejected + try/catch so a flush failure cannot leave the process hanging. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # CHANGELOG.md
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates AutoCollectExceptions to avoid turning exception storms into ingestion request-rate amplifiers by removing per-exception forceFlush() calls and introducing client-side rate limiting for exception telemetry, while still flushing on the terminal crash path.
Changes:
- Removed per-exception
LoggerProvider.forceFlush()and restricted flushing to the terminal exit path. - Added a 50/min token-bucket style limiter that suppresses excess exception telemetry and emits one per-window summary exception on refill.
- Added unit tests for non-terminal no-flush behavior and the new rate-limiting + summary behavior, plus a changelog entry.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/logs/exceptions.ts |
Implements rate limiting, suppressed-count summary emission, and terminal-only flush with hardened failure handling. |
test/unitTests/logs/exceptions.tests.ts |
Adds unit tests covering non-terminal no-flush and rate-limit + summary emission behavior. |
CHANGELOG.md |
Documents the new rate limiting and terminal-only flush behavior under Unreleased bug fixes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rads-1996
approved these changes
May 21, 2026
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.
AutoCollectExceptions previously invoked LoggerProvider.forceFlush() on every uncaughtException and unhandledRejection, with no client-side rate limit. Under exception storms this bypassed BatchLogRecordProcessor batching and amplified request rate against the ingestion endpoint.
Changes:
Remove per-exception forceFlush; flush only on the terminal exit path (sole listener + reThrow).
Add a 50/min token-bucket rate limiter; emit a single summary trackException on bucket refill reporting the suppressed count.
Always record the terminal/fatal exception, bypassing the rate limit.
Harden terminal flush with onRejected + try/catch so a flush failure cannot leave the process hanging.