Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion src/sentry/api/event_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@

aggregate_key = key open_paren spaces function_args? spaces closed_paren
function_args = aggregate_param (spaces comma spaces !comma aggregate_param?)*
aggregate_param = explicit_tag_key_aggregate_param / quoted_aggregate_param / raw_aggregate_param
aggregate_param = explicit_tag_key_aggregate_param / query_aggregate_param / quoted_aggregate_param / raw_aggregate_param
query_aggregate_param = "`" (quoted_value / ~r"[^`\"]+")* "`"
raw_aggregate_param = ~r"[^()\t\n, \"]+"
quoted_aggregate_param = '"' ('\\"' / ~r'[^\t\n\"]')* '"'
explicit_tag_key_aggregate_param = explicit_tag_key / explicit_number_tag_key / explicit_string_tag_key / explicit_boolean_tag_key
Expand Down Expand Up @@ -1642,6 +1643,9 @@ def visit_function_args(
def visit_aggregate_param(self, node: Node, children: tuple[str]) -> str:
return children[0]

def visit_query_aggregate_param(self, node: Node, children: object) -> str:
return node.text

def visit_raw_aggregate_param(self, node: Node, children: object) -> str:
return node.text

Expand Down
15 changes: 15 additions & 0 deletions tests/sentry/api/test_event_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,21 @@ def test_paren_expression(self) -> None:
SearchFilter(key=SearchKey(name="z"), operator="=", value=SearchValue(raw_value="1")),
]

def test_conditional_aggregate_query_argument(self) -> None:
for predicate in [
"x:1 AND (y:2 OR z:3)",
'span.description:"hello world"',
'gen_ai.tool.name:["search docs",calculator]',
r'span.description:"say \"hello\""',
]:
assert parse_search_query(f"count_if(`{predicate}`,span.duration):>0") == [
AggregateFilter(
key=AggregateKey(f"count_if(`{predicate}`, span.duration)"),
operator=">",
value=SearchValue(0.0),
)
]

def test_paren_expression_of_empty_string(self) -> None:
assert parse_search_query('("")') == parse_search_query('""') == []

Expand Down
Loading