Skip to content

Commit a77f457

Browse files
authored
ref(auto_source): Prepare code for different levels of granularity (#89211)
1 parent 97d6fe0 commit a77f457

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/sentry/issues/auto_source_code_config/code_mapping.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from sentry.utils import metrics
1919
from sentry.utils.event_frames import EventFrame, try_munge_frame_path
2020

21-
from .constants import METRIC_PREFIX
21+
from .constants import METRIC_PREFIX, STACK_ROOT_MAX_LEVEL
2222
from .integration_utils import InstallationNotFoundError, get_installation
2323
from .utils.platform import PlatformConfig
2424

@@ -591,17 +591,18 @@ def get_path_from_module(module: str, abs_path: str) -> tuple[str, str]:
591591
if "." not in module:
592592
raise DoesNotFollowJavaPackageNamingConvention
593593

594-
parts = module.split(".")
594+
# Gets rid of the class name
595+
parts = module.rsplit(".", 1)[0].split(".")
596+
dirpath = "/".join(parts)
595597

596-
if len(parts) > 2:
598+
if len(parts) >= STACK_ROOT_MAX_LEVEL:
597599
# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
598600
# stack_root: com/example/
599601
# file_path: com/example/foo/bar/Baz.kt
600-
stack_root = "/".join(parts[:2])
601-
file_path = "/".join(parts[:-1]) + "/" + abs_path
602+
stack_root = "/".join(parts[:STACK_ROOT_MAX_LEVEL])
602603
else:
603604
# a.Bar, Bar.kt -> stack_root: a/, file_path: a/Bar.kt
604605
stack_root = parts[0] + "/"
605-
file_path = f"{stack_root}{abs_path}"
606606

607+
file_path = f"{dirpath}/{abs_path}"
607608
return stack_root, file_path

src/sentry/issues/auto_source_code_config/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
METRIC_PREFIX = "auto_source_code_config"
77
DERIVED_ENHANCEMENTS_OPTION_KEY = "sentry:derived_grouping_enhancements"
88
SUPPORTED_INTEGRATIONS = ["github"]
9+
STACK_ROOT_MAX_LEVEL = 2
910

1011
# Any new languages should also require updating the stacktraceLink.tsx
1112
# The extensions do not need to be exhaustive but only include the ones that show up in stacktraces

src/sentry/issues/auto_source_code_config/in_app_stack_trace_rules.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from sentry.models.project import Project
77
from sentry.utils import metrics
88

9-
from .constants import DERIVED_ENHANCEMENTS_OPTION_KEY, METRIC_PREFIX
9+
from .constants import DERIVED_ENHANCEMENTS_OPTION_KEY, METRIC_PREFIX, STACK_ROOT_MAX_LEVEL
1010

1111
logger = logging.getLogger(__name__)
1212

@@ -48,9 +48,10 @@ def generate_rule_for_code_mapping(code_mapping: CodeMapping) -> str:
4848
if stacktrace_root == "":
4949
raise ValueError("Stacktrace root is empty")
5050

51-
parts = stacktrace_root.rstrip("/").split("/", 2)
51+
parts = stacktrace_root.rstrip("/").split("/")
52+
5253
# We only want the first two parts
53-
module = ".".join(parts[:2])
54+
module = ".".join(parts[:STACK_ROOT_MAX_LEVEL])
5455

5556
if module == "":
5657
raise ValueError("Module is empty")

0 commit comments

Comments
 (0)