Browse Source

fix: Correct timestamps for all samples to accomodate relay update (#19140)

* fix: Correct timestamps for all samples to accomodate relay update

* fix tests

* fix another test
Markus Unterwaditzer 4 years ago
parent
commit
c1a186b8ed
2 changed files with 12 additions and 12 deletions
  1. 0 2
      src/sentry/testutils/factories.py
  2. 12 10
      src/sentry/utils/samples.py

+ 0 - 2
src/sentry/testutils/factories.py

@@ -516,8 +516,6 @@ class Factories(object):
     def store_event(data, project_id, assert_no_errors=True, sent_at=None):
         # Like `create_event`, but closer to how events are actually
         # ingested. Prefer to use this method over `create_event`
-        if sent_at is None:
-            sent_at = timezone.now()
         manager = EventManager(data, sent_at=sent_at)
         manager.normalize()
         if assert_no_errors:

+ 12 - 10
src/sentry/utils/samples.py

@@ -149,16 +149,18 @@ def load_data(platform, default=None, sample_name=None):
     if platform in ("csp", "hkpk", "expectct", "expectstaple"):
         return data
 
-    # Transaction events need timestamp data set to something current.
-    if platform == "transaction":
-        now = timezone.now()
-        now_time = to_timestamp(now)
-        start_time = to_timestamp(now - timedelta(seconds=2))
-        data.setdefault("timestamp", now_time)
-        data.setdefault("start_timestamp", start_time)
-        for span in data["spans"]:
-            span.setdefault("timestamp", now_time)
-            span.setdefault("start_timestamp", start_time)
+    # Fixing up timestamps for all events
+    now = timezone.now()
+    now_time = to_timestamp(now)
+    start_time = to_timestamp(now - timedelta(seconds=2))
+    data.setdefault("timestamp", now_time)
+
+    if data.get("type") == "transaction":
+        data["start_timestamp"] = start_time
+
+    for span in data.get("spans") or ():
+        span.setdefault("timestamp", now_time)
+        span.setdefault("start_timestamp", start_time)
 
     data["platform"] = platform
     # XXX: Message is a legacy alias for logentry. Do not overwrite if set.