Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/sentry/utils/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import asyncio
import copy
import logging
import re
import sys
import typing
from collections.abc import Generator, Mapping, Sequence, Sized
Expand Down Expand Up @@ -92,6 +93,12 @@
"/api/0/auth/validate/": 0.0,
}

# List of (compiled_pattern, sample_rate) tried in order when no exact route matches.
SAMPLED_ROUTE_PATTERNS: list[tuple[re.Pattern[str], float]] = [
# Temporary: monitoring AI Conversations rollout
(re.compile(r"^/api/0/organizations/[^/]+/ai-conversations/"), 1.0),
]

if settings.ADDITIONAL_SAMPLED_TASKS:
SAMPLED_TASKS.update(settings.ADDITIONAL_SAMPLED_TASKS)

Expand Down Expand Up @@ -182,8 +189,12 @@ def get_project_key():

def traces_sampler(sampling_context):
wsgi_path = sampling_context.get("wsgi_environ", {}).get("PATH_INFO")
if wsgi_path and wsgi_path in SAMPLED_ROUTES:
return SAMPLED_ROUTES[wsgi_path]
if wsgi_path:
if wsgi_path in SAMPLED_ROUTES:
return SAMPLED_ROUTES[wsgi_path]
for pattern, rate in SAMPLED_ROUTE_PATTERNS:
if pattern.search(wsgi_path):
return rate

# Apply sample_rate from custom_sampling_context
custom_sample_rate = sampling_context.get("sample_rate")
Expand Down
Loading