Browse Source

fix(spans): Handle invalid spans fields query (#83111)

- Add a handle_query_errors around when we execute the tag_values query
so we return an error message instead of erroring
- fixes SENTRY-3G6J
William Mak 2 months ago
parent
commit
1a4c25c867

+ 2 - 1
src/sentry/api/endpoints/organization_spans_fields.py

@@ -232,7 +232,8 @@ class OrganizationSpansFieldValuesEndpoint(OrganizationSpansFieldsEndpointBase):
                 max_span_tag_values=max_span_tag_values,
             )
 
-        tag_values = executor.execute()
+        with handle_query_errors():
+            tag_values = executor.execute()
 
         tag_values.sort(key=lambda tag: tag.value)
 

+ 29 - 0
tests/sentry/api/endpoints/test_organization_spans_fields.py

@@ -3,6 +3,7 @@ from uuid import uuid4
 
 from django.urls import reverse
 
+from sentry.exceptions import InvalidSearchQuery
 from sentry.testutils.cases import APITestCase, BaseSpansTestCase
 from sentry.testutils.helpers.datetime import before_now
 
@@ -840,6 +841,34 @@ class OrganizationSpansTagKeyValuesEndpointTest(BaseSpansTestCase, APITestCase):
             assert response.status_code == 200, response.data
             assert response.data == []
 
+    @mock.patch(
+        "sentry.api.endpoints.organization_spans_fields.EAPSpanFieldValuesAutocompletionExecutor.execute",
+        side_effect=InvalidSearchQuery,
+    )
+    @mock.patch(
+        "sentry.api.endpoints.organization_spans_fields.SpanFieldValuesAutocompletionExecutor.execute",
+        side_effect=InvalidSearchQuery,
+    )
+    def test_invalid_query(self, mock_executor_1, mock_executor_2):
+        timestamp = before_now(days=0, minutes=10).replace(microsecond=0)
+        self.store_segment(
+            self.project.id,
+            uuid4().hex,
+            uuid4().hex,
+            span_id=uuid4().hex[:16],
+            organization_id=self.organization.id,
+            parent_span_id=None,
+            timestamp=timestamp,
+            transaction="foo",
+            duration=100,
+            exclusive_time=100,
+            tags={"tag": "foo"},
+            is_eap=self.is_eap,
+        )
+
+        response = self.do_request("tag")
+        assert response.status_code == 400, response.data
+
 
 class OrganizationEAPSpansTagKeyValuesEndpointTest(OrganizationSpansTagKeyValuesEndpointTest):
     is_eap = True