Skip to content

Attach lock context to overloaded exceptions for better metrics#18

Draft
dpep wants to merge 1 commit into
mainfrom
codex/raise-overloaded-exception-with-lock
Draft

Attach lock context to overloaded exceptions for better metrics#18
dpep wants to merge 1 commit into
mainfrom
codex/raise-overloaded-exception-with-lock

Conversation

@dpep
Copy link
Copy Markdown
Owner

@dpep dpep commented Apr 23, 2026

Motivation

  • Make it possible for middleware to report lock-based metrics (capacity/contention) even when a limiter raises an overloaded error by carrying lock context on the exception.
  • Improve observability of overload events so StatsD and tracing middleware can record meaningful stats instead of only noting an error.

Description

  • Add Berater::Overloaded#lock and an initializer that accepts a Lock instance so overload exceptions can carry lock details.
  • Update concrete limiters (StaticLimiter, RateLimiter, ConcurrencyLimiter, Inhibitor) to raise Overloaded.new(Lock.new(...)) with the appropriate capacity and count/contention when the request is refused.
  • Update Statsd middleware to use error.lock when no lock was returned so lock gauges are emitted for overload events.
  • Update Trace middleware to retrieve lock info from error.lock when applicable so traces can still tag contention on overloads, and update specs to assert the new behavior.

Testing

  • Updated middleware specs spec/middleware/statsd_spec.rb and spec/middleware/trace_spec.rb to validate lock-based metrics/tags are captured from the overloaded exception's lock; these specs were modified alongside code changes.
  • Attempted to run relevant specs with bundle exec rspec spec/middleware/statsd_spec.rb spec/middleware/trace_spec.rb spec/concurrency_limiter_spec.rb spec/rate_limiter_spec.rb spec/static_limiter_spec.rb spec/inhibitor_spec.rb but the environment cannot run them here: bundler: command not found: rspec.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant