You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR splits the previously unified canceled rate-limit outcome into two distinct values — canceled for context.Canceled and deadline_exceeded for context.DeadlineExceeded — giving operators finer-grained observability on the ratelimit.outcome span attribute without changing any error-handling behavior.
Replaces the boolean isContextEnded helper with rateLimitContextOutcome, which returns the concrete RateLimitOutcome value directly, eliminating the hardcoded RateLimitOutcomeCanceled at the call site.
Adds RateLimitOutcomeDeadline = "deadline_exceeded" to attrs.go alongside the existing outcome constants.
Covers the new classification logic with a focused parallel table-driven test for all three cases (canceled, deadline_exceeded, and non-context errors).
Confidence Score: 5/5
Safe to merge — the change is purely additive, only affects span attribute values, and all existing error-handling behavior is preserved.
The refactor is well-scoped: a new string constant, a small function replacing a boolean helper, and tests that cover all three branches including the zero-value default. No request-lifecycle behaviour changes, no new failure modes, and the existing integration tests still cover the middleware end-to-end.
Replaces isContextEnded bool helper with rateLimitContextOutcome returning the specific outcome value; logic is correct, uses errors.Is for wrapping, and the early-return (no HTTP response) on context errors is preserved intentionally.
internal/middleware/ratelimit_test.go
Adds TestRateLimitContextOutcome covering canceled, deadline_exceeded, and a non-context error; test for the "other" case correctly validates both ok=false and outcome="" zero value.
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[store.Increment returns error] --> B{rateLimitContextOutcome}
B -->|errors.Is Canceled| C[outcome = canceled]
B -->|errors.Is DeadlineExceeded| D[outcome = deadline_exceeded]
B -->|other| E[outcome = store_error]
C --> F[SetAttributes on span
return — no HTTP response]
D --> F
E --> G[SetAttributes on span
log error
503 Service Unavailable]
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
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.
deadline_exceededvalue forratelimit.outcomecontext.Canceledandcontext.DeadlineExceededthrough separateRateLimitOutcomevalueskv.Storefailure log pathrateLimitContextOutcomeclassification