From 84038d7afc5b3856c900d6a9c895457526606fb5 Mon Sep 17 00:00:00 2001 From: William Mak Date: Fri, 22 Nov 2024 14:57:16 -0500 Subject: [PATCH] fix(eap): Add test for explore homepage - Adds a test that matches the explore's homepage query --- src/sentry/search/eap/columns.py | 5 ++ .../test_organization_events_span_indexed.py | 54 ++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/sentry/search/eap/columns.py b/src/sentry/search/eap/columns.py index 4d2a7fc0458145..9c4a779a1f458e 100644 --- a/src/sentry/search/eap/columns.py +++ b/src/sentry/search/eap/columns.py @@ -255,6 +255,11 @@ def simple_measurements_field(field) -> ResolvedColumn: internal_name="sentry.segment_name", search_type="string", ), + ResolvedColumn( + public_alias="transaction.span_id", + internal_name="sentry.segment_id", + search_type="string", + ), ResolvedColumn( public_alias="replay.id", internal_name="sentry.replay_id", diff --git a/tests/snuba/api/endpoints/test_organization_events_span_indexed.py b/tests/snuba/api/endpoints/test_organization_events_span_indexed.py index ae2fa86b8edd6b..370eb6b4444326 100644 --- a/tests/snuba/api/endpoints/test_organization_events_span_indexed.py +++ b/tests/snuba/api/endpoints/test_organization_events_span_indexed.py @@ -1,4 +1,5 @@ import uuid +from datetime import datetime from unittest import mock import pytest @@ -754,7 +755,6 @@ def test_orderby_alias(self): "dataset": self.dataset, } ) - assert response.status_code == 200, response.content data = response.data["data"] meta = response.data["meta"] @@ -771,6 +771,58 @@ def test_orderby_alias(self): ] assert meta["dataset"] == self.dataset + @pytest.mark.querybuilder + def test_explore_sample_query(self): + spans = [ + self.create_span( + {"description": "foo", "sentry_tags": {"status": "success"}}, + start_ts=self.ten_mins_ago, + ), + self.create_span( + {"description": "bar", "sentry_tags": {"status": "invalid_argument"}}, + start_ts=self.nine_mins_ago, + ), + ] + self.store_spans( + spans, + is_eap=self.is_eap, + ) + response = self.do_request( + { + "field": [ + "id", + "project", + "span.op", + "span.description", + "span.duration", + "timestamp", + "trace", + "transaction.span_id", + ], + # This is to skip INP spans + "query": "!transaction.span_id:00", + "orderby": "timestamp", + "statsPeriod": "1h", + "project": self.project.id, + "dataset": self.dataset, + } + ) + assert response.status_code == 200, response.content + data = response.data["data"] + meta = response.data["meta"] + assert len(data) == 2 + for source, result in zip(spans, data): + assert result["id"] == source["span_id"], "id" + assert result["span.duration"] == 1000.0, "duration" + assert result["span.op"] == "", "op" + assert result["span.description"] == source["description"], "description" + assert datetime.fromisoformat(result["timestamp"]).timestamp() == pytest.approx( + source["end_timestamp_precise"], abs=5 + ), "timestamp" + assert result["transaction.span_id"] == source["segment_id"], "transaction.span_id" + assert result["project"] == result["project.name"] == self.project.slug, "project" + assert meta["dataset"] == self.dataset + def test_span_status(self): self.store_spans( [