feat: expose rate limit headers via on_rate_limit_info callback#41
Merged
Conversation
Surface x-ratelimit-* headers from successful responses so callers can build observability around the rate limit (warn at thresholds, emit metrics) without inspecting internals. - Extend RateLimitInfo with method, url, and usage_pct() helper - Add RateLimitInfoCallback type alias (Arc<dyn Fn + Send + Sync>) - Add on_rate_limit_info option on Config and ConfigBuilder - Parse and emit headers on every successful response in make_request - Ship logging_rate_limit_observer as a zero-config observer (defaults: 80/90/95%) - Callback panics are caught with std::panic::catch_unwind so they cannot break requests - Fix pre-existing clippy collapsible_if warnings in invoice and credit_note examples - Backward-compatible: option is optional, default behavior unchanged
8ebc8c6 to
5c73b17
Compare
jdenquin
approved these changes
May 11, 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 onConfigso callers can readx-ratelimit-*headers from successful responses. Today the SDK drops them on 2xx, which makes 80/90/95% threshold observability impossible without inspecting internals. The 429 path is unchanged. Mirrors PRs getlago/lago-python-client#393, getlago/lago-go-client#336, getlago/lago-ruby-client#347, and getlago/lago-javascript-client#86.Notes for review
Option<Arc<dyn Fn(&RateLimitInfo) + Send + Sync>>so the client staysCloneandSend + Sync.std::panic::catch_unwindand logged so a buggy observer can't break a request.RateLimitInfogainedmethod,urlfields and ausage_pct()helper.Defaultis now derived so existing struct-literal tests use..Default::default().clippy::collapsible_ifwarnings in unrelated examples (invoice.rs,credit_note.rs) were folded in to keep CI green; happy to split out if you'd prefer.Tests
5 new tests in
client.rs(usage_pct happy + unusable, success path, missing-headers, panic recovery) plus 3 inobservability.rs. Backward-compatible — all existing tests pass after..Default::default()updates.