3
3
from typing import Any , Literal , cast
4
4
from uuid import uuid1
5
5
6
+ import pytest
7
+
6
8
from sentry .eventstore .models import Event
7
9
from sentry .seer .similarity .utils import (
8
10
BASE64_ENCODED_PREFIXES ,
11
+ MAX_FRAME_COUNT ,
9
12
SEER_ELIGIBLE_PLATFORMS ,
13
+ TooManyOnlySystemFramesException ,
10
14
_is_snipped_context_line ,
11
15
event_content_is_seer_eligible ,
12
16
filter_null_from_string ,
@@ -670,18 +674,18 @@ def test_chained_too_many_frames_minified_js_frame_limit(self):
670
674
)
671
675
672
676
def test_chained_too_many_exceptions (self ):
673
- """Test that we restrict number of chained exceptions to 30 ."""
677
+ """Test that we restrict number of chained exceptions to MAX_FRAME_COUNT ."""
674
678
data_chained_exception = copy .deepcopy (self .CHAINED_APP_DATA )
675
679
data_chained_exception ["app" ]["component" ]["values" ][0 ]["values" ] = [
676
680
self .create_exception (
677
681
exception_type_str = "Exception" ,
678
682
exception_value = f"exception { i } message!" ,
679
683
frames = self .create_frames (num_frames = 1 , context_line_factory = lambda i : f"line { i } " ),
680
684
)
681
- for i in range (1 , 32 )
685
+ for i in range (1 , MAX_FRAME_COUNT + 2 )
682
686
]
683
687
stacktrace_str = get_stacktrace_string (data_chained_exception )
684
- for i in range (2 , 32 ):
688
+ for i in range (2 , MAX_FRAME_COUNT + 2 ):
685
689
assert f"exception { i } message!" in stacktrace_str
686
690
assert "exception 1 message!" not in stacktrace_str
687
691
@@ -710,9 +714,35 @@ def test_no_app_no_system(self):
710
714
stacktrace_str = get_stacktrace_string (data )
711
715
assert stacktrace_str == ""
712
716
713
- def test_over_30_contributing_frames (self ):
714
- """Check that when there are over 30 contributing frames, the last 30 are included."""
717
+ def test_too_many_system_frames_single_exception (self ):
718
+ data_system = copy .deepcopy (self .BASE_APP_DATA )
719
+ data_system ["system" ] = data_system .pop ("app" )
720
+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][0 ][
721
+ "values"
722
+ ] += self .create_frames (MAX_FRAME_COUNT + 1 , True )
723
+
724
+ with pytest .raises (TooManyOnlySystemFramesException ):
725
+ get_stacktrace_string (data_system )
726
+
727
+ def test_too_many_system_frames_chained_exception (self ):
728
+ data_system = copy .deepcopy (self .CHAINED_APP_DATA )
729
+ data_system ["system" ] = data_system .pop ("app" )
730
+ # Split MAX_FRAME_COUNT across the two exceptions
731
+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][0 ]["values" ][0 ][
732
+ "values"
733
+ ] += self .create_frames (MAX_FRAME_COUNT // 2 , True )
734
+ data_system ["system" ]["component" ]["values" ][0 ]["values" ][1 ]["values" ][0 ][
735
+ "values"
736
+ ] += self .create_frames (MAX_FRAME_COUNT // 2 , True )
737
+
738
+ with pytest .raises (TooManyOnlySystemFramesException ):
739
+ get_stacktrace_string (data_system )
715
740
741
+ def test_too_many_in_app_contributing_frames (self ):
742
+ """
743
+ Check that when there are over MAX_FRAME_COUNT contributing frames, the last MAX_FRAME_COUNT
744
+ are included.
745
+ """
716
746
data_frames = copy .deepcopy (self .BASE_APP_DATA )
717
747
# Create 30 contributing frames, 1-20 -> last 10 should be included
718
748
data_frames ["app" ]["component" ]["values" ][0 ]["values" ][0 ]["values" ] = self .create_frames (
@@ -739,7 +769,7 @@ def test_over_30_contributing_frames(self):
739
769
for i in range (41 , 61 ):
740
770
num_frames += 1
741
771
assert ("test = " + str (i ) + "!" ) in stacktrace_str
742
- assert num_frames == 30
772
+ assert num_frames == MAX_FRAME_COUNT
743
773
744
774
def test_too_many_frames_minified_js_frame_limit (self ):
745
775
"""Test that we restrict fully-minified stacktraces to 20 frames, and all other stacktraces to 30 frames."""
0 commit comments