Skip to content

Commit 4622c74

Browse files
Zylphrexandrewshie-sentry
authored andcommitted
fix(eap): Numeric attribute filtering in snql eap (#82472)
RPC isn't fully stable yet so fix this in SnQL first.
1 parent 818a027 commit 4622c74

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/sentry/search/events/builder/spans_indexed.py

+7
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ class SpansEAPQueryBuilder(BaseQueryBuilder):
7171
def __init__(self, *args, **kwargs):
7272
super().__init__(*args, **kwargs)
7373

74+
def get_field_type(self, field: str) -> str | None:
75+
tag_match = constants.TYPED_TAG_KEY_RE.search(field)
76+
field_type = tag_match.group("type") if tag_match else None
77+
if field_type == "number":
78+
return "number"
79+
return super().get_field_type(field)
80+
7481
def resolve_field(self, raw_field: str, alias: bool = False) -> Column:
7582
# try the typed regex first
7683
if len(raw_field) > constants.MAX_TAG_KEY_LENGTH:

tests/snuba/api/endpoints/test_organization_events_span_indexed.py

+30-2
Original file line numberDiff line numberDiff line change
@@ -1474,8 +1474,36 @@ def test_span_data_fields_http_resource(self):
14741474
},
14751475
}
14761476

1477-
def test_other_category_span(self):
1478-
super().test_other_category_span()
1477+
def test_filtering_numeric_attr(self):
1478+
span_1 = self.create_span(
1479+
{"description": "foo"},
1480+
measurements={"foo": {"value": 30}},
1481+
start_ts=self.ten_mins_ago,
1482+
)
1483+
span_2 = self.create_span(
1484+
{"description": "foo"},
1485+
measurements={"foo": {"value": 10}},
1486+
start_ts=self.ten_mins_ago,
1487+
)
1488+
self.store_spans([span_1, span_2], is_eap=self.is_eap)
1489+
1490+
response = self.do_request(
1491+
{
1492+
"field": ["tags[foo,number]"],
1493+
"query": "span.duration:>=0 tags[foo,number]:>20",
1494+
"project": self.project.id,
1495+
"dataset": self.dataset,
1496+
}
1497+
)
1498+
1499+
assert response.status_code == 200, response.content
1500+
assert response.data["data"] == [
1501+
{
1502+
"id": span_1["span_id"],
1503+
"project.name": self.project.slug,
1504+
"tags[foo,number]": 30,
1505+
},
1506+
]
14791507

14801508

14811509
class OrganizationEventsEAPRPCSpanEndpointTest(OrganizationEventsEAPSpanEndpointTest):

0 commit comments

Comments
 (0)