fix: match rate limits by data category not envelope item type#5412
Draft
jamescrosswell wants to merge 4 commits into
Draft
fix: match rate limits by data category not envelope item type#5412jamescrosswell wants to merge 4 commits into
jamescrosswell wants to merge 4 commits into
Conversation
Rate limits in the `X-Sentry-Rate-Limits` header are keyed by data category (e.g. `error`, `monitor`, `log_item`, `metric_bucket`), which is not always the same as the envelope item type (`event`, `check_in`, `log`, `statsd`). `RateLimitCategory.Matches` compared the category name against the raw item type, so limits for errors, check-ins and logs were silently ignored — the SDK kept sending that data instead of backing off, and client reports mis-attributed the resulting drops to `default`. - Map every emitted item type to its correct data category, and add the missing `monitor`/`log_item`/`trace_metric`/`metric_bucket` constants - Match rate limits against the item's data category - Record dropped logs/metrics under their real category in client reports - Never rate-limit client reports (they are the `internal` category) Closes #4535 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jamescrosswell
commented
Jul 20, 2026
Comment on lines
+20
to
+22
| // Rate limits are keyed by data category (e.g. "error", "monitor", "metric_bucket"), which is not | ||
| // always the same as the envelope item type (e.g. "event", "check_in", "statsd"). Compare against the | ||
| // item's data category so limits for those categories are honoured rather than silently ignored. |
Collaborator
Author
There was a problem hiding this comment.
Keep this concise...
Suggested change
| // Rate limits are keyed by data category (e.g. "error", "monitor", "metric_bucket"), which is not | |
| // always the same as the envelope item type (e.g. "event", "check_in", "statsd"). Compare against the | |
| // item's data category so limits for those categories are honoured rather than silently ignored. | |
| // Rate limits are keyed by data category (e.g. "error", "monitor", "metric_bucket") |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## fix/5406-pin-xcode-26.6 #5412 +/- ##
===========================================================
+ Coverage 74.60% 74.63% +0.03%
===========================================================
Files 512 512
Lines 18666 18674 +8
Branches 3659 3657 -2
===========================================================
+ Hits 13925 13937 +12
+ Misses 3867 3864 -3
+ Partials 874 873 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The 10.0.302 workload ships the iOS SDK pack 26.5.10301, which requires Xcode 26.6. CI was pinning Xcode 26.5, causing iOS/MacCatalyst builds and device tests to fail. The macos-26 runner already used by these jobs has Xcode 26.6 available, so switch the pin to it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Dependabot bumped only codeql-action/init to 4.37.1, leaving analyze on 4.37.0. CodeQL requires all steps use the same version, so analyze failed with "Loaded a configuration file for version '4.37.1', but running version '4.37.0'". Pin analyze to the same v4.37.1 SHA. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
jamescrosswell
commented
Jul 21, 2026
|
|
||
| public RateLimitCategory(string name) => Name = name; | ||
|
|
||
| public bool Matches(EnvelopeItem item) |
Collaborator
Author
There was a problem hiding this comment.
This could be simplified to a lambda that simply returns IsMatchAll || string.Equals(...
…x/rate-limit-data-categories
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.
Summary
Rate limits in the
X-Sentry-Rate-Limitsheader are keyed by data category (error,monitor,log_item,metric_bucket, …), which is not always the same as the envelope item type (event,check_in,log,statsd).RateLimitCategory.Matchescompared the server's category name against the raw envelope item type, so category-specific limits whose name differs from the item type were silently ignored:Matchesresulteventerrorcheck_inmonitorloglog_itemThe practical effect: when Sentry rate-limited errors, the SDK didn't recognise the limit, kept sending, got
429d downstream, and client reports mis-attributed the drops todefaultinstead of the real category. This is the concern raised in #4535 — mishandling categories can cause the most important data (errors) to be dropped rather than cleanly backed off.Changes
RateLimitCategory.Matchesnow compares the limit against the item's data category rather than the raw item type — soerror/monitor/log_itemlimits are honoured. The special-case forstatsd→metric_bucketis no longer needed.EnvelopeItem.DataCategorymaps every emitted item type to its correct category:check_in→monitor,log→log_item,trace_metric→trace_metric,statsd→metric_bucket. Client reports (client_report) now map tointernalso they are never dropped by adefaultrate limit.BatchProcessorrecords dropped logs/metrics under their real category (log_item/trace_metric) instead ofdefault.DataCategorygains the missingmonitor/log_item/trace_metric/metric_bucketconstants and the doc link is updated.error, notevent) and to guard against the regression (item-type strings must not match).Verified: full
Sentry.Testssuite passes onnet9.0(2465 passed, 4 environment-skips).Closes #4535