Skip to content

Commit e9dd314

Browse files
armenzgChristinarlong
authored andcommitted
fix(auto_source_config): Remove unintended rules (#88952)
To keep the project option accurate we will be removing the unintended rules.
1 parent 6ee92e5 commit e9dd314

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/sentry/issues/auto_source_code_config/constants.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,26 @@
2828
"clojure": {"extensions": ["clj", "cljs", "cljc"]},
2929
"groovy": {"extensions": ["groovy"]},
3030
}
31+
32+
33+
# This list needs to be updated when new packages are added to the list
34+
UNINTENDED_RULES = [
35+
"stack.module:akka.** +app",
36+
"stack.module:com.fasterxml.** +app",
37+
"stack.module:com.microsoft.** +app",
38+
"stack.module:com.sun.** +app",
39+
"stack.module:feign.** +app",
40+
"stack.module:io.opentelemetry.** +app",
41+
"stack.module:jdk.** +app",
42+
"stack.module:oauth.** +app",
43+
"stack.module:org.apache.** +app",
44+
"stack.module:org.glassfish.** +app",
45+
"stack.module:org.jboss.** +app",
46+
"stack.module:org.jdesktop.** +app",
47+
"stack.module:org.postgresql.** +app",
48+
"stack.module:org.springframework.** +app",
49+
"stack.module:org.web3j.** +app",
50+
"stack.module:reactor.core.** +app",
51+
"stack.module:scala.** +app",
52+
"stack.module:sun.** +app",
53+
]

src/sentry/issues/auto_source_code_config/task.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
SCMIntegrationInteractionType,
1717
)
1818
from sentry.issues.auto_source_code_config.code_mapping import CodeMapping, CodeMappingTreesHelper
19+
from sentry.issues.auto_source_code_config.constants import UNINTENDED_RULES
1920
from sentry.locks import locks
2021
from sentry.models.organization import Organization
2122
from sentry.models.project import Project
@@ -78,6 +79,10 @@ def process_event(
7879
if not platform_config.is_supported():
7980
return [], []
8081

82+
# This is a temporary solution to remove unintended rules across the board
83+
if platform_config.creates_in_app_stack_trace_rules():
84+
remove_unintended_rules(project)
85+
8186
frames_to_process = get_frames_to_process(event.data, platform)
8287
if not frames_to_process:
8388
return [], []
@@ -203,6 +208,23 @@ def create_configurations(
203208
return code_mappings, in_app_stack_trace_rules
204209

205210

211+
def remove_unintended_rules(project: Project) -> None:
212+
"""
213+
Remove unintended rules from the project's automatic grouping enhancements.
214+
"""
215+
key = "sentry:automatic_grouping_enhancements"
216+
in_app_stack_trace_rules = project.get_option(key, default="").split("\n")
217+
if not in_app_stack_trace_rules:
218+
return
219+
220+
# Remove rules that are not in the code mappings
221+
for rule in in_app_stack_trace_rules:
222+
if rule in UNINTENDED_RULES:
223+
in_app_stack_trace_rules.remove(rule)
224+
225+
project.update_option(key, "\n".join(in_app_stack_trace_rules))
226+
227+
206228
def create_code_mapping(
207229
code_mapping: CodeMapping,
208230
repository: Repository | None,

tests/sentry/issues/auto_source_code_config/test_process_event.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,3 +815,19 @@ def test_categorized_frames_are_not_processed(self) -> None:
815815
)
816816
assert dry_run_code_mappings != []
817817
assert in_app_stack_trace_rules != []
818+
819+
@with_feature({"organizations:auto-source-code-config-java-enabled": True})
820+
def test_unintended_rules_are_removed(self) -> None:
821+
"""Test that unintended rules will be removed without affecting other rules"""
822+
key = "sentry:automatic_grouping_enhancements"
823+
# Let's assume that the package was not categorized, thus, we created a rule for it
824+
self.project.update_option(key, "stack.module:akka.** +app\nstack.module:foo.bar.** +app")
825+
# This module is categorized, thus, we won't attempt derivation for it
826+
frame = self.frame(module="com.sun.Activity", abs_path="Activity.java", in_app=False)
827+
event = self.create_event([frame], self.platform)
828+
829+
# The rule will be removed after calling this
830+
process_event(self.project.id, event.group_id, event.event_id)
831+
rules = self.project.get_option(key)
832+
# Other rules are not affected
833+
assert rules.split("\n") == ["stack.module:foo.bar.** +app"]

0 commit comments

Comments
 (0)