Add rejecting/throttling policy to query metrics and span#8196
Open
phacops wants to merge 2 commits into
Open
Conversation
When an allocation policy rejects a query, the `rejected_query` Datadog metric was only tagged with `storage_key`, making it impossible to tell which policy caused the rejection. Add a `policy` tag with the rejecting policy's class name, and record the same value as `rejected_by_policy` on the allocation-policy span. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NjS4o6maJ2cQs2qFJmNRjS
MeredithAnya
approved these changes
Jul 17, 2026
Mirror the rejection change for the throttling path: the throttled_query metric now carries a `policy` tag with the throttling policy's class name, and the allocation-policy span records `throttled_by_policy`. The successful_query path has no single responsible policy, so it is left unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NjS4o6maJ2cQs2qFJmNRjS
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.
When an allocation policy rejects or throttles a query in
_apply_allocation_policies_quota, the emitted Datadog metrics were only tagged withstorage_key. That made it impossible to tell from the metric which policy caused the rejection/throttle when multiple policies are in play for a storage.This PR surfaces the responsible policy's class name in the metrics and span:
db_query.rejected_querymetric — newpolicytag alongside the existingstorage_key.db_query.throttled_querymetric — newpolicytag alongside the existingstorage_key.allocation_policyspan — newrejected_by_policy/throttled_by_policydata fields.The responsible policy is already tracked locally as
rejection_quota_and_policy/throttle_quota_and_policy, so this just surfaces it. The rejection path falls back to"unknown"in the defensive case wherecan_runis false but no rejecting policy was captured. Thesuccessful_querypath has no single responsible policy, so it is left unchanged.Testing
test_db_query_with_rejecting_allocation_policyto assertrejected_querycarries bothstorage_keyandpolicytags.test_apply_allocation_policies_quota_sets_throttle_policyto assertthrottled_querycarries bothstorage_keyandpolicytags.Both tests pass locally.
Legal Boilerplate
Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.
🤖 Generated with Claude Code
https://claude.ai/code/session_01NjS4o6maJ2cQs2qFJmNRjS