@@ -81,7 +81,8 @@ def _process_and_assert_code_mapping(
8181 expected_source_root : str ,
8282 expected_repo_name : str = REPO1 ,
8383 expected_num_code_mappings : int = 1 ,
84- ) -> None :
84+ expected_in_app_stack_trace_rules : list [str ] | None = None ,
85+ ) -> GroupEvent :
8586 with (
8687 patch (f"{ CLIENT } .get_tree" , side_effect = create_mock_get_tree (repo_trees )),
8788 patch (f"{ CLIENT } .get_remaining_api_requests" , return_value = 500 ),
@@ -94,8 +95,9 @@ def _process_and_assert_code_mapping(
9495 repositories_count = Repository .objects .all ().count ()
9596 code_mappings_count = RepositoryProjectPathConfig .objects .all ().count ()
9697 event = self .create_event (frames , platform )
97- process_event (self .project .id , event .group_id , event .event_id )
98-
98+ _ , in_app_stack_trace_rules = process_event (
99+ self .project .id , event .group_id , event .event_id
100+ )
99101 code_mappings = RepositoryProjectPathConfig .objects .all ()
100102 assert len (code_mappings ) == expected_num_code_mappings
101103 code_mapping = code_mappings .filter (
@@ -118,14 +120,20 @@ def _process_and_assert_code_mapping(
118120 mock_incr .assert_any_call (
119121 key = f"{ METRIC_PREFIX } .code_mapping.created" , tags = tags , sample_rate = 1.0
120122 )
123+ if expected_in_app_stack_trace_rules is not None :
124+ # XXX: Grab it from the option
125+ assert expected_in_app_stack_trace_rules == in_app_stack_trace_rules
126+
127+ # Returning this is useful to inspect hash changes
128+ return event
121129
122130 def _process_and_assert_no_code_mapping (
123131 self ,
124132 * , # Force keyword arguments
125133 repo_trees : Mapping [str , Sequence [str ]],
126134 frames : Sequence [Mapping [str , str | bool ]],
127135 platform : str ,
128- ) -> list [CodeMapping ]:
136+ ) -> tuple [ list [CodeMapping ], list [ str ] ]:
129137 with (
130138 patch (f"{ CLIENT } .get_tree" , side_effect = create_mock_get_tree (repo_trees )),
131139 patch (f"{ CLIENT } .get_remaining_api_requests" , return_value = 500 ),
@@ -136,7 +144,9 @@ def _process_and_assert_no_code_mapping(
136144 patch ("sentry.utils.metrics.incr" ) as mock_incr ,
137145 ):
138146 event = self .create_event (frames , platform )
139- code_mappings = process_event (self .project .id , event .group_id , event .event_id )
147+ code_mappings , in_app_stack_trace_rules = process_event (
148+ self .project .id , event .group_id , event .event_id
149+ )
140150 assert not RepositoryProjectPathConfig .objects .exists ()
141151 platform_config = PlatformConfig (platform )
142152 dry_run = platform_config .is_dry_run_platform ()
@@ -152,7 +162,7 @@ def _process_and_assert_no_code_mapping(
152162 tags = {"platform" : event .platform , "dry_run" : dry_run },
153163 sample_rate = 1.0 ,
154164 )
155- return code_mappings
165+ return code_mappings , in_app_stack_trace_rules
156166
157167 def frame (self , filename : str , in_app : bool | None = True ) -> dict [str , str | bool ]:
158168 frame : dict [str , str | bool ] = {"filename" : filename }
@@ -242,7 +252,7 @@ def test_dry_run_platform(self) -> None:
242252 patch (f"{ CODE_ROOT } .utils.PlatformConfig.is_dry_run_platform" , return_value = True ),
243253 ):
244254 # No code mapping will be stored, however, we get what would have been created
245- code_mappings = self ._process_and_assert_no_code_mapping (
255+ code_mappings , _ = self ._process_and_assert_no_code_mapping (
246256 repo_trees = {REPO1 : [file_in_repo ]},
247257 frames = [self .frame (frame_filename , True )],
248258 platform = platform ,
@@ -591,7 +601,7 @@ class TestJavaDeriveCodeMappings(LanguageSpecificDeriveCodeMappings):
591601
592602 def test_very_short_module_name (self ) -> None :
593603 # No code mapping will be stored, however, we get what would have been created
594- code_mappings = self ._process_and_assert_no_code_mapping (
604+ code_mappings , in_app_stack_trace_rules = self ._process_and_assert_no_code_mapping (
595605 repo_trees = {REPO1 : ["src/a/SomeShortPackageNameClass.java" ]},
596606 frames = [
597607 {
@@ -604,10 +614,11 @@ def test_very_short_module_name(self) -> None:
604614 assert len (code_mappings ) == 1
605615 assert code_mappings [0 ].stacktrace_root == "a/"
606616 assert code_mappings [0 ].source_path == "src/a/"
617+ assert in_app_stack_trace_rules == ["stack.module:a.** +app" ]
607618
608619 def test_handles_dollar_sign_in_module (self ) -> None :
609620 # No code mapping will be stored, however, we get what would have been created
610- code_mappings = self ._process_and_assert_no_code_mapping (
621+ code_mappings , in_app_stack_trace_rules = self ._process_and_assert_no_code_mapping (
611622 repo_trees = {REPO1 : ["src/com/example/foo/Bar.kt" ]},
612623 frames = [{"module" : "com.example.foo.Bar$InnerClass" , "abs_path" : "Bar.kt" }],
613624 platform = self .platform ,
0 commit comments