Skip to content

perf(sdk): Use Django URL resolution for view-based trace sampling#115878

Draft
vgrozdanic wants to merge 1 commit into
masterfrom
vj/sampled-views-resolve
Draft

perf(sdk): Use Django URL resolution for view-based trace sampling#115878
vgrozdanic wants to merge 1 commit into
masterfrom
vj/sampled-views-resolve

Conversation

@vgrozdanic
Copy link
Copy Markdown
Member

@vgrozdanic vgrozdanic commented May 20, 2026

Summary

Alternative to #115874. Instead of maintaining a parallel list of compiled regexes that duplicate URL patterns from urls.py, this uses Django's resolve() to match the request path against the existing URL conf and then looks up the resolved URL name in a SAMPLED_VIEWS dict.

  • O(1) dict lookup instead of linear regex scan
  • No regex duplication — sampling config references URL names defined in urls.py, so they can't drift out of sync
  • Same fallthrough behavior — exact-match SAMPLED_ROUTES is checked first, then SAMPLED_VIEWS via resolve, then the rest of the sampler logic

Samples AI Conversations endpoints at 100% for rollout monitoring.

Routes covered

SAMPLED_VIEWS: dict[str, float] = {
    "sentry-api-0-organization-ai-conversations": 1.0,
    "sentry-api-0-organization-ai-conversation-details": 1.0,
}

Add SAMPLED_VIEWS dict keyed by Django URL name, replacing the regex
pattern approach with resolve()-based lookups. This avoids duplicating
URL regexes and gives O(1) dict lookup instead of linear regex scans.

Samples AI Conversations endpoints at 100% for rollout monitoring.
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant