Browse Source

fix(suspect-spans): Should find span groups prefixed with 0s (#29546)

The span group is a base16 string, and can start with 0s. This means that when
checking string equality, the 0 prefix can result in false when it does match.
Tony Xiao 3 years ago
parent
commit
404bf57bf4

+ 3 - 2
src/sentry/api/endpoints/organization_events_spans_performance.py

@@ -193,7 +193,7 @@ class SuspectSpan:
             "project": self.project,
             "transaction": self.transaction,
             "op": self.op,
-            "group": self.group,
+            "group": self.group.rjust(16, "0"),
             "frequency": self.frequency,
             "count": self.count,
             "sumExclusiveTime": self.sum_exclusive_time,
@@ -340,6 +340,7 @@ def get_example_transaction(
     span_op: str,
     span_group: str,
 ) -> ExampleTransaction:
+    span_group_id = int(span_group, 16)
     event = eventstore.get_event_by_id(project_id, transaction_id)
     data = event.data
 
@@ -359,7 +360,7 @@ def get_example_transaction(
     matching_spans = [
         span
         for span in chain([root_span], data.get("spans", []))
-        if span["op"] == span_op and span["hash"] == span_group
+        if span["op"] == span_op and int(span["hash"], 16) == span_group_id
     ]
 
     # get the first non-None description

+ 28 - 0
tests/snuba/api/endpoints/test_organization_events_spans_performance.py

@@ -433,3 +433,31 @@ class OrganizationEventsSpansPerformanceEndpointBase(APITestCase, SnubaTestCase)
             assert "sort=-sumExclusiveTime" in link
             # last page does not have a next page, only previous
             assert info["results"] == ("true" if info["rel"] == "previous" else "false")
+
+    @pytest.mark.skip("setting snuba config is too slow")
+    def test_span_group_prefixed_with_zeros(self):
+        self.update_snuba_config_ensure({"write_span_columns_projects": f"[{self.project.id}]"})
+
+        trace_context = {
+            "op": "http.server",
+            "hash": "00" + "ab" * 7,
+            "exclusive_time": 4.0,
+        }
+
+        event = self.create_event(trace_context=trace_context)
+
+        with self.feature(self.FEATURES):
+            response = self.client.get(
+                self.url,
+                data={
+                    "project": self.project.id,
+                    "sort": "-p99ExclusiveTime",
+                    "per_page": 1,
+                },
+                format="json",
+            )
+
+        assert response.status_code == 200, response.content
+        results = self.suspect_span_results("percentiles", event)
+        results["group"] = "00" + "ab" * 7
+        self.assert_suspect_span(response.data, [results])