Browse Source

Fix transaction truncation

James Kiger 11 months ago
parent
commit
7831a4d34e

+ 6 - 0
apps/event_ingest/tests/test_process_issue_event.py

@@ -67,6 +67,12 @@ class IssueEventIngestTestCase(EventIngestTestCase):
             ).exists()
         )
 
+    def test_transaction_truncation(self):
+        data = self.get_json_data("events/test_data/py_hi_event.json")
+        data["culprit"] = "x" * 201
+        self.process_events(data)
+        self.assertTrue(IssueEvent.objects.first())
+
     def test_message_empty_param_list(self):
         self.process_events(
             [

+ 3 - 1
sentry/eventtypes/error.py

@@ -1,5 +1,6 @@
 from django.utils.encoding import force_str
 
+from sentry.constants import MAX_CULPRIT_LENGTH
 from sentry.culprit import generate_culprit
 from sentry.stacktraces.functions import get_function_name_for_frame
 from sentry.stacktraces.processing import get_crash_frame_from_event_data
@@ -67,9 +68,10 @@ class ErrorEvent(BaseEvent):
             return "{}: {}".format(ty, str(metadata["value"]))
 
     def get_location(self, data):
-        return force_str(
+        loc_string = force_str(
             data.get("culprit")
             or data.get("transaction")
             or generate_culprit(data)
             or ""
         )
+        return truncatechars(loc_string, MAX_CULPRIT_LENGTH)

+ 1 - 1
sentry/utils/strings.py

@@ -3,7 +3,7 @@ from django.utils.encoding import smart_str
 
 def truncatechars(value: str, chars=100):
     """Truncate string and append …"""
-    return (value[:chars] + "…") if len(value) > chars else value
+    return (value[: chars - 3] + "…") if len(value) > chars else value
 
 
 def strip(value):