Skip to content

Add rejecting/throttling policy to query metrics and span#8196

Open
phacops wants to merge 2 commits into
masterfrom
claude/policy-span-datadog-metric-1utx9m
Open

Add rejecting/throttling policy to query metrics and span#8196
phacops wants to merge 2 commits into
masterfrom
claude/policy-span-datadog-metric-1utx9m

Conversation

@phacops

@phacops phacops commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

When an allocation policy rejects or throttles a query in _apply_allocation_policies_quota, the emitted Datadog metrics were only tagged with storage_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_query metric — new policy tag alongside the existing storage_key.
  • db_query.throttled_query metric — new policy tag alongside the existing storage_key.
  • allocation_policy span — new rejected_by_policy / throttled_by_policy data 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 where can_run is false but no rejecting policy was captured. The successful_query path has no single responsible policy, so it is left unchanged.

Testing

  • Extended test_db_query_with_rejecting_allocation_policy to assert rejected_query carries both storage_key and policy tags.
  • Extended test_apply_allocation_policies_quota_sets_throttle_policy to assert throttled_query carries both storage_key and policy tags.

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

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
@phacops
phacops requested a review from a team as a code owner July 17, 2026 19:25
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
@phacops phacops changed the title Add rejecting policy to rejected_query metric and span Add rejecting/throttling policy to query metrics and span Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants