Skip to content

Commit 7e3d0a8

Browse files
evanhNisanthan Nanthakumar
authored and
Nisanthan Nanthakumar
committed
feat(discover) Switch trace and span id to use columns instead of context
Have the trace_id and span_id use the built in columns instead of the context array.
1 parent d2f069e commit 7e3d0a8

File tree

6 files changed

+56
-5
lines changed

6 files changed

+56
-5
lines changed

src/sentry/api/endpoints/organization_events.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import logging
44
import six
5+
import uuid
56
from functools import partial
67
from rest_framework.response import Response
78
from rest_framework.exceptions import ParseError
@@ -164,9 +165,19 @@ def handle_data(self, request, organization, project_ids, results):
164165

165166
# TODO(mark) move all of this result formatting into discover.query()
166167
# once those APIs are used across the application.
167-
if "transaction.status" in first_row:
168+
tests = {
169+
"transaction.status": "transaction.status" in first_row,
170+
"trace": "trace" in first_row,
171+
}
172+
if any(tests.values()):
168173
for row in results:
169-
row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(row["transaction.status"])
174+
if tests["transaction.status"]:
175+
row["transaction.status"] = SPAN_STATUS_CODE_TO_NAME.get(
176+
row["transaction.status"]
177+
)
178+
if tests["trace"]:
179+
row["trace"] = uuid.UUID(row["trace"]).hex
180+
170181
if not ("project.id" in first_row or "projectid" in first_row):
171182
return results
172183
fields = request.GET.getlist("field")

src/sentry/api/event_search.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import absolute_import
22

33
import re
4+
import uuid
45
from collections import namedtuple
56
from copy import deepcopy
67
from datetime import datetime
@@ -584,6 +585,21 @@ def convert_search_filter_to_snuba_query(search_filter):
584585
)
585586
)
586587
return [name, search_filter.operator, internal_value]
588+
elif name == "trace":
589+
if not search_filter.value.raw_value:
590+
operator = "IS NULL" if search_filter.operator == "=" else "IS NOT NULL"
591+
return [name, operator, None]
592+
593+
try:
594+
return [
595+
name,
596+
search_filter.operator,
597+
six.text_type(uuid.UUID(search_filter.value.raw_value)),
598+
]
599+
except Exception:
600+
raise InvalidSearchQuery(
601+
"Invalid value for the trace condition. Value must be a hexadecimal UUID string."
602+
)
587603
else:
588604
value = (
589605
int(to_timestamp(value)) * 1000

src/sentry/snuba/events.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ class Columns(Enum):
212212
TRACE_ID = Column(
213213
"events.contexts[trace.trace_id]",
214214
"contexts[trace.trace_id]",
215-
"contexts[trace.trace_id]",
216-
"contexts[trace.trace_id]",
215+
"trace_id",
216+
"trace_id",
217217
"trace",
218218
)
219219
SPAN_ID = Column(

tests/sentry/api/test_event_search.py

+4
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ def test_transaction_status_invalid(self):
10791079
assert "Invalid value" in six.text_type(err)
10801080
assert "cancelled," in six.text_type(err)
10811081

1082+
def test_trace_id(self):
1083+
result = get_filter("trace:{}".format("a0fa8803753e40fd8124b21eeb2986b5"))
1084+
assert result.conditions == [["trace", "=", "a0fa8803-753e-40fd-8124-b21eeb2986b5"]]
1085+
10821086

10831087
class ResolveFieldListTest(unittest.TestCase):
10841088
def test_non_string_field_error(self):

tests/snuba/api/endpoints/test_organization_events_v2.py

+20
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,23 @@ def test_transaction_event_type(self):
592592
assert response.data["meta"]["transaction.duration"] == "duration"
593593
assert response.data["meta"]["transaction.status"] == "string"
594594
assert response.data["data"][0]["transaction.status"] == "ok"
595+
596+
def test_trace_columns(self):
597+
self.login_as(user=self.user)
598+
599+
project = self.create_project()
600+
data = load_data("transaction")
601+
data["timestamp"] = iso_format(before_now(minutes=1))
602+
data["start_timestamp"] = iso_format(before_now(minutes=1, seconds=5))
603+
self.store_event(data=data, project_id=project.id)
604+
605+
with self.feature("organizations:events-v2"):
606+
response = self.client.get(
607+
self.url,
608+
format="json",
609+
data={"field": ["trace"], "query": "event.type:transaction"},
610+
)
611+
assert response.status_code == 200, response.content
612+
assert len(response.data["data"]) == 1
613+
assert response.data["meta"]["trace"] == "string"
614+
assert response.data["data"][0]["trace"] == data["contexts"]["trace"]["trace_id"]

tests/snuba/search/test_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ def test_query(query):
13761376
elif key in IssueSearchVisitor.date_keys:
13771377
val = "2019-01-01"
13781378
else:
1379-
val = "hello"
1379+
val = "abadcafedeadbeefdeaffeedabadfeed"
13801380
test_query("!%s:%s" % (key, val))
13811381

13821382
test_query("%s:%s" % (key, val))

0 commit comments

Comments
 (0)