Skip to content

Commit ee7bae8

Browse files
authored
feat(detectors): Add filtered URL check to detectors that use urlparse (#97694)
follow up to #97104 - adds the logic to other detectors
1 parent ac2fec6 commit ee7bae8

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

src/sentry/performance_issues/detectors/consecutive_http_detector.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from sentry.issues.issue_occurrence import IssueEvidence
77
from sentry.models.organization import Organization
88
from sentry.models.project import Project
9-
from sentry.performance_issues.detectors.utils import get_max_span_duration, get_total_span_duration
9+
from sentry.performance_issues.detectors.utils import (
10+
get_max_span_duration,
11+
get_total_span_duration,
12+
has_filtered_url,
13+
)
1014
from sentry.utils.event import is_event_from_browser_javascript_sdk
1115
from sentry.utils.safe import get_path
1216

@@ -163,6 +167,9 @@ def _is_eligible_http_span(self, span: Span) -> bool:
163167
if any([x in description for x in ["_next/static/", "_next/data/", "googleapis.com"]]):
164168
return False
165169

170+
if has_filtered_url(self._event, span):
171+
return False
172+
166173
return True
167174

168175
def _fingerprint(self) -> str:

src/sentry/performance_issues/detectors/experiments/n_plus_one_api_calls_detector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
parameterize_url,
2121
parameterize_url_with_result,
2222
)
23-
from sentry.performance_issues.detectors.utils import get_total_span_duration
23+
from sentry.performance_issues.detectors.utils import get_total_span_duration, has_filtered_url
2424
from sentry.performance_issues.performance_problem import PerformanceProblem
2525
from sentry.performance_issues.types import Span
2626

@@ -128,6 +128,9 @@ def _is_span_eligible(self, span: Span) -> bool:
128128
if not url:
129129
return False
130130

131+
if has_filtered_url(self._event, span):
132+
return False
133+
131134
# Once most users update their SDKs to use the latest standard, we
132135
# won't have to do this, since the URLs will be sent in as `span.data`
133136
# in a parsed format

src/sentry/performance_issues/detectors/http_overhead_detector.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sentry.issues.issue_occurrence import IssueEvidence
1010
from sentry.models.organization import Organization
1111
from sentry.models.project import Project
12+
from sentry.performance_issues.detectors.utils import has_filtered_url
1213

1314
from ..base import (
1415
DetectorType,
@@ -115,13 +116,8 @@ def _is_span_eligible(self, span: Span) -> bool:
115116
return False
116117

117118
# Check if any spans have filtered URLs
118-
event_spans = self._event.get("spans", [])
119-
span_index = str(event_spans.index(span) if span in event_spans else -1)
120-
meta = self._event.get("_meta", {}).get("spans", {})
121-
if span_index in meta:
122-
has_filtered_url = meta[span_index].get("data", {}).get("url", {})
123-
if has_filtered_url:
124-
return False
119+
if has_filtered_url(self._event, span):
120+
return False
125121

126122
return True
127123

src/sentry/performance_issues/detectors/n_plus_one_api_calls_detector.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
get_url_from_span,
2424
parameterize_url,
2525
)
26-
from sentry.performance_issues.detectors.utils import get_total_span_duration
26+
from sentry.performance_issues.detectors.utils import get_total_span_duration, has_filtered_url
2727
from sentry.performance_issues.performance_problem import PerformanceProblem
2828
from sentry.performance_issues.types import Span
2929

@@ -128,6 +128,10 @@ def _is_span_eligible(self, span: Span) -> bool:
128128
if not url:
129129
return False
130130

131+
# Check if any spans have filtered URLs
132+
if has_filtered_url(self._event, span):
133+
return False
134+
131135
# Once most users update their SDKs to use the latest standard, we
132136
# won't have to do this, since the URLs will be sent in as `span.data`
133137
# in a parsed format

src/sentry/performance_issues/detectors/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
from typing import Any
23

34
from sentry.performance_issues.base import get_span_duration
45

@@ -22,3 +23,12 @@ def escape_transaction(transaction: str) -> str:
2223
transaction = re.sub(r'"', r"\"", transaction)
2324
transaction = re.sub(r"\*", r"\*", transaction)
2425
return transaction
26+
27+
28+
def has_filtered_url(event: dict[str, Any], span: Span) -> bool:
29+
event_spans = event.get("spans", [])
30+
span_index = str(event_spans.index(span) if span in event_spans else -1)
31+
meta = event.get("_meta", {}).get("spans", {})
32+
if span_index in meta and meta[span_index].get("data", {}).get("url", {}):
33+
return True
34+
return False

0 commit comments

Comments
 (0)