Skip to content

Rate-limit AutoCollectExceptions and drop per-exception forceFlush#1499

Merged
JacksonWeber merged 3 commits into
microsoft:mainfrom
JacksonWeber:fix/ado-37976881-exceptions-rate-limit
May 21, 2026
Merged

Rate-limit AutoCollectExceptions and drop per-exception forceFlush#1499
JacksonWeber merged 3 commits into
microsoft:mainfrom
JacksonWeber:fix/ado-37976881-exceptions-rate-limit

Conversation

@JacksonWeber
Copy link
Copy Markdown
Contributor

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.

JacksonWeber and others added 2 commits May 20, 2026 19:36
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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/logs/exceptions.ts
Comment thread src/logs/exceptions.ts
@JacksonWeber JacksonWeber merged commit 2bf123f into microsoft:main May 21, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants