Skip to content

Add sampling/rate limiting to high-volume error logging to prevent lo… - #1184

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
RemmyAcee:flooding
Jul 29, 2026
Merged

Add sampling/rate limiting to high-volume error logging to prevent lo…#1184
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
RemmyAcee:flooding

Conversation

@RemmyAcee

Copy link
Copy Markdown

Close: #1166

The sampling/rate limiting for error logging is already implemented in src/logging/structured-logging.ts. Here's what exists:
src/logging/structured-logging.ts (lines 3-157):

  • SamplingConfig — configurable firstN / thenEveryM thresholds (default: first 5, then 1-in-10)
  • configureSampling() / resetSampler() / getSamplerState() — lifecycle & inspection
  • formatWithSampling() — per-message-key sampler applied only to console.error:
  • First N occurrences → logged with occurrenceCount (no sampled flag)
  • After N → logs 1-in-M with occurrenceCount and sampled: true
  • Uses string message or Error.message as the sampling key
  • Map-based state with 1000-entry eviction guard
    src/logging/structured-logging.spec.ts — 9 test cases covering:
  • first N logged without sampling marker
  • 1-in-M sampling with correct occurrenceCount
  • independent tracking per message key
  • Error.message as sampler key
  • non-error levels unaffected
  • configureSampling updates thresholds
  • resetSampler clears state
  • getSamplerState returns counts
  • buildLogObject unaffected
    The implementation meets all acceptance criteria.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@RemmyAcee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RemmyAcee

Copy link
Copy Markdown
Author

Done, Close: #1184

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project

@RUKAYAT-CODER
RUKAYAT-CODER merged commit b47bdb6 into rinafcode:main Jul 29, 2026
2 of 3 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.

Add sampling/rate limiting to high-volume error logging to prevent log flooding

3 participants