Browse Source

feat(tracing): Add profile id to the useSpans response (#67054)

- This updates the response of the trace endpoint to include the events
profile id if its available
William Mak 1 year ago
parent
commit
ade986006d

+ 2 - 0
src/sentry/api/endpoints/organization_events_trace.py

@@ -333,6 +333,7 @@ class TraceEvent:
         if self.span_serialized:
             result["timestamp"] = self.event["precise.finish_ts"]
             result["start_timestamp"] = self.event["precise.start_ts"]
+            result["profile_id"] = self.event["profile.id"]
         if self.nodestore_event:
             result["timestamp"] = self.nodestore_event.data.get("timestamp")
             result["start_timestamp"] = self.nodestore_event.data.get("start_timestamp")
@@ -438,6 +439,7 @@ def query_trace_data(
         "precise.finish_ts",
         "project",
         "project.id",
+        "profile.id",
         "trace.span",
         "trace.parent_span",
         'to_other(trace.parent_span, "", 0, 1) AS root',

+ 2 - 0
tests/snuba/api/endpoints/test_organization_events_trace.py

@@ -52,6 +52,7 @@ class OrganizationEventsTraceEndpointBase(OrganizationEventsEndpointTestBase):
         )
         data["transaction"] = transaction
         data["contexts"]["trace"]["parent_span_id"] = parent_span_id
+        data["contexts"]["profile"] = {"profile_id": uuid4().hex}
         if span_id:
             data["contexts"]["trace"]["span_id"] = span_id
         if measurements:
@@ -806,6 +807,7 @@ class OrganizationEventsTraceEndpointTest(OrganizationEventsTraceEndpointBase):
         assert result["transaction"] == event_data.transaction, message
         assert result["event_id"] == event_data.event_id
         assert result["start_timestamp"] == event_data.data["start_timestamp"]
+        assert result["profile_id"] == event_data.data["contexts"]["profile"]["profile_id"]
 
     def assert_trace_data(self, root, gen2_no_children=True):
         """see the setUp docstring for an idea of what the response structure looks like"""