Browse Source

chore(suspect-spans): Add some suspect spans data for mock data (#31168)

Tony Xiao 3 years ago
parent
commit
e599ee8851
1 changed files with 16 additions and 4 deletions
  1. 16 4
      src/sentry/utils/samples.py

+ 16 - 4
src/sentry/utils/samples.py

@@ -9,6 +9,7 @@ import pytz
 from sentry.constants import DATA_ROOT, INTEGRATION_ID_TO_PLATFORM_DATA
 from sentry.event_manager import EventManager
 from sentry.interfaces.user import User as UserInterface
+from sentry.spans.grouping.utils import hash_values
 from sentry.utils import json
 from sentry.utils.canonical import CanonicalKeyDict
 from sentry.utils.dates import to_timestamp
@@ -295,8 +296,9 @@ def create_sample_event(
 
     if not data:
         return
-    if "parent_span_id" in kwargs:
-        data["contexts"]["trace"]["parent_span_id"] = kwargs.pop("parent_span_id")
+    for key in ["parent_span_id", "hash", "exclusive_time"]:
+        if key in kwargs:
+            data["contexts"]["trace"][key] = kwargs.pop(key)
 
     data.update(kwargs)
     return create_sample_event_basic(data, project.id, raw=raw)
@@ -319,17 +321,23 @@ def create_trace(slow, start_timestamp, timestamp, user, trace_id, parent_span_i
     new_end = timestamp - timedelta(milliseconds=random_normal(50, 25, 10))
     for child in data["children"]:
         span_id = uuid4().hex[:16]
+        description = f"GET {child['transaction']}"
+        duration = random_normal((new_end - new_start).total_seconds(), 0.25, 0.01)
         spans.append(
             {
                 "same_process_as_parent": True,
                 "op": "http",
-                "description": f"GET {child['transaction']}",
+                "description": description,
                 "data": {
-                    "duration": random_normal((new_end - new_start).total_seconds(), 0.25, 0.01),
+                    "duration": duration,
                     "offset": 0.02,
                 },
                 "span_id": span_id,
                 "trace_id": trace_id,
+                "hash": hash_values([description]),
+                # not the best but just set the exclusive time
+                # equal to the duration to get some span data
+                "exclusive_time": duration,
             }
         )
         create_trace(
@@ -376,6 +384,10 @@ def create_trace(slow, start_timestamp, timestamp, user, trace_id, parent_span_i
         span_id=current_span_id,
         trace=trace_id,
         spans=spans,
+        hash=hash_values([data["transaction"]]),
+        # not the best but just set the exclusive time
+        # equal to the duration to get some span data
+        exclusive_time=(timestamp - start_timestamp).total_seconds(),
     )
     # try to give clickhouse some breathing room
     if slow: