feat: expose rate limit headers via on_rate_limit_info callback#347
Merged
Conversation
7cdb19e to
eca14c2
Compare
Surface x-ratelimit-* headers from successful responses so callers can build observability around the rate limit (warn at thresholds, emit metrics) without inspecting internals. - Add Lago::Api::RateLimitInfo with usage_pct - Add on_rate_limit_info option on Client and Connection - Parse and emit headers on every non-429 response in Connection - Ship Lago::Api::LoggingRateLimitObserver as a zero-config observer (defaults: 80/90/95%) - Callback errors are rescued and warned so they cannot break requests - Backward-compatible: callback is optional, default behavior unchanged
eca14c2 to
6c82ecd
Compare
This was referenced May 5, 2026
Merged
vincent-pochet
approved these changes
May 5, 2026
Address review feedback from @vincent-pochet on PR #347: declare the method string once per action method and reuse it for both execute_request and http_client.send_request, instead of repeating the literal twice.
vincent-pochet
approved these changes
May 5, 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.
Adds an optional
on_rate_limit_infocallback onLago::Api::Clientso callers can readx-ratelimit-*headers from successful responses. Today the SDK drops them on 2xx, which makes 80/90/95% threshold observability impossible without poking at internals. The 429 path (viaRateLimitError) is unchanged. Mirrors PRs getlago/lago-python-client#393 and getlago/lago-go-client#336.Notes for review
warnso a buggy observer can't break a request.Tests
New
spec/lago/api/rate_limit_observability_spec.rbwith coverage forRateLimitInfo(usage_pct + parse), the callback path (success, missing headers, error swallow, single-fire after 429-then-200),LoggingRateLimitObserver, and Client wiring. Existing rate limit specs untouched.