Skip to content

Commit f1622bf

Browse files
authored
fix(on_demand): skip spec generation for error widgets (#59424)
1 parent c857d91 commit f1622bf

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

src/sentry/snuba/metrics/extraction.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,8 +485,10 @@ def _is_on_demand_supported_search_filter(token: QueryToken) -> bool:
485485
if not _SEARCH_TO_RELAY_OPERATORS.get(token.operator):
486486
return False
487487

488-
return not _is_excluding_transactions(token) and _is_on_demand_supported_field(
489-
token.key.name
488+
return (
489+
not _is_excluding_transactions(token)
490+
and not _is_error_field(token.key.name)
491+
and _is_on_demand_supported_field(token.key.name)
490492
)
491493

492494
if isinstance(token, ParenExpression):
@@ -496,11 +498,13 @@ def _is_on_demand_supported_search_filter(token: QueryToken) -> bool:
496498

497499

498500
def _is_excluding_transactions(token: SearchFilter) -> bool:
499-
return (
500-
token.key.name == "event.type"
501-
and token.operator == "!="
502-
and token.value.raw_value == "transaction"
503-
)
501+
if token.key.name != "event.type":
502+
return False
503+
504+
is_not_transaction = token.operator == "!=" and token.value.raw_value == "transaction"
505+
is_error_or_default = token.operator == "=" and token.value.raw_value in ["error", "default"]
506+
507+
return is_not_transaction or is_error_or_default
504508

505509

506510
def _is_standard_metrics_field(field: str) -> bool:
@@ -512,6 +516,10 @@ def _is_standard_metrics_field(field: str) -> bool:
512516
)
513517

514518

519+
def _is_error_field(token: str) -> bool:
520+
return token.startswith("error.")
521+
522+
515523
def _is_standard_metrics_search_term(field: str) -> bool:
516524
return field in _STANDARD_METRIC_FIELDS
517525

tests/sentry/snuba/test_extraction.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,21 @@
4444
True,
4545
), # transaction.duration query is on-demand
4646
("count[)", "", False), # Malformed aggregate should return false
47+
(
48+
"count()",
49+
"event.type:error transaction.duration:>0",
50+
False,
51+
), # event.type:error not supported by metrics
52+
(
53+
"count()",
54+
"event.type:default transaction.duration:>0",
55+
False,
56+
), # event.type:error not supported by metrics
57+
(
58+
"count()",
59+
"error.handled:true transaction.duration:>0",
60+
False,
61+
), # error.handled is an error search term
4762
],
4863
)
4964
def test_should_use_on_demand(agg, query, result):

0 commit comments

Comments
 (0)