Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/sentry/issues/auto_source_code_config/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
DERIVED_ENHANCEMENTS_OPTION_KEY = "sentry:derived_grouping_enhancements"
SUPPORTED_INTEGRATIONS = [IntegrationProviderSlug.GITHUB.value]
STACK_ROOT_MAX_LEVEL = 4
# Stacktrace roots that match one of these will have an extra level of granularity
# com.au, co.uk, org.uk, gov.uk, net.uk, edu.uk, ct.uk
# This list does not have to be exhaustive as the fallback is two levels of granularity
SECOND_LEVEL_TLDS = ("com", "co", "org", "gov", "net", "edu")

# Any new languages should also require updating the stacktraceLink.tsx
# The extensions do not need to be exhaustive but only include the ones that show up in stacktraces
Expand Down
27 changes: 10 additions & 17 deletions src/sentry/issues/auto_source_code_config/frame_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
from collections.abc import Mapping, Sequence
from typing import Any

from sentry import options
from sentry.integrations.source_code_management.repo_trees import get_extension

from .constants import SECOND_LEVEL_TLDS, STACK_ROOT_MAX_LEVEL
from .constants import STACK_ROOT_MAX_LEVEL
from .errors import (
DoesNotFollowJavaPackageNamingConvention,
MissingModuleOrAbsPath,
Expand Down Expand Up @@ -157,25 +156,19 @@ def get_path_from_module(module: str, abs_path: str) -> tuple[str, str]:


def get_granularity(parts: Sequence[str]) -> int:
# a.Bar, Bar.kt -> stack_root: a/, file_path: a/Bar.kt
# a.Bar, Bar.kt -> stack_root: a/, file_path: a/Bar.kt
granularity = 1

if len(parts) > 1:
# com.example.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/foo/
# stack_root: com/example/foo/bar/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All cases inside of this if/clause will use STACK_ROOT_MAX_LEVEL rather than STACK_ROOT_MAX_LEVEL - 1 in some cases.

This will create a lot more code mappings (storage cost) but it will make everything more consistent an easier to debug (human cost & quality).

We're already incurring this cost since this morning when I enabled the option. I'm just making it clearer in the code.

# file_path: com/example/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL - 1

if parts[1] in SECOND_LEVEL_TLDS:
# uk.co.example.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: uk/co/example/foo/
# file_path: uk/co/example/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL

elif options.get("auto_source_code_config.multi_module_java"):
# com.example.multi.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/multi/foo/
# file_path: com/example/multi/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL
# uk.co.example.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: uk/co/example/foo/
# file_path: uk/co/example/foo/bar/Baz.kt
# com.example.multi.foo.bar.Baz$InnerClass, Baz.kt ->
# stack_root: com/example/multi/foo/
# file_path: com/example/multi/foo/bar/Baz.kt
granularity = STACK_ROOT_MAX_LEVEL

return granularity
7 changes: 0 additions & 7 deletions src/sentry/options/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,13 +903,6 @@
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"auto_source_code_config.multi_module_java",
type=Bool,
default=False,
flags=FLAG_AUTOMATOR_MODIFIABLE,
)

register(
"issues.severity.first-event-severity-calculation-projects-allowlist",
type=Sequence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ def test_java_raises_exception(
with pytest.raises(expected_exception):
create_frame_info(frame, "java")

# Only necessary while auto_source_code_config.multi_module_java is used
@pytest.mark.django_db
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We added this in the previous PR since we add to check options.

@pytest.mark.parametrize(
"frame, expected_stack_root, expected_normalized_path",
[
Expand Down Expand Up @@ -119,6 +117,12 @@ def test_java_raises_exception(
"foo/bar/Baz", # The path does not use the abs_path
id="invalid_abs_path_dollar_sign",
),
pytest.param(
{"module": "foo.Baz", "abs_path": "foo"},
"foo/", # Single-depth stack root
"foo/Baz",
id="granularity_1",
),
],
)
def test_java_valid_frames(
Expand Down
49 changes: 10 additions & 39 deletions tests/sentry/issues/auto_source_code_config/test_process_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,32 +1004,6 @@ def test_categorized_frames_are_not_processed(self) -> None:
expected_new_in_app_stack_trace_rules=["stack.module:android.app.** +app"],
)

def test_multi_module_with_old_granularity(self) -> None:
java_module_prefix = "com.example.multi"
module_prefix = java_module_prefix.replace(".", "/") + "/"
repo_trees = {
REPO1: [
f"modules/modX/{module_prefix}foo/Bar.kt",
f"modules/modY/{module_prefix}bar/Baz.kt",
]
}
frames = [
self.frame_from_module(f"{java_module_prefix}.foo.Bar", "Bar.kt"),
self.frame_from_module(f"{java_module_prefix}.bar.Baz", "Baz.kt"),
]
self._process_and_assert_configuration_changes(
repo_trees=repo_trees,
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
# It's missing the extra granularity
# It's going to pick modY since it is the first frame processed, thus,
# the other frame will not have a working code mapping
self.code_mapping("com/example/multi/", "modules/modY/com/example/multi/")
],
expected_new_in_app_stack_trace_rules=["stack.module:com.example.** +app"],
)

def test_multi_module(self) -> None:
# Some Java projects have all modules under the same com/foo/bar directory
# however, some projects have different modules under different directories
Expand All @@ -1051,16 +1025,13 @@ def test_multi_module(self) -> None:
self.frame_from_module(f"{java_module_prefix}.foo.Bar", "Bar.kt"),
self.frame_from_module(f"{java_module_prefix}.bar.Baz", "Baz.kt"),
]
with self.options({"auto_source_code_config.multi_module_java": True}):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just removing the option and left indenting.

self._process_and_assert_configuration_changes(
repo_trees=repo_trees,
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
self.code_mapping(f"{module_prefix}foo/", f"modules/modX/{module_prefix}foo/"),
self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"),
],
expected_new_in_app_stack_trace_rules=[
f"stack.module:{java_module_prefix}.** +app"
],
)
self._process_and_assert_configuration_changes(
repo_trees=repo_trees,
frames=frames,
platform=self.platform,
expected_new_code_mappings=[
self.code_mapping(f"{module_prefix}foo/", f"modules/modX/{module_prefix}foo/"),
self.code_mapping(f"{module_prefix}bar/", f"modules/modY/{module_prefix}bar/"),
],
expected_new_in_app_stack_trace_rules=[f"stack.module:{java_module_prefix}.** +app"],
)
2 changes: 0 additions & 2 deletions tests/sentry/issues/ownership/test_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def test_matcher_test_threads() -> None:
assert not Matcher("url", "*.py").test(data, munged_data)


# Only necessary while auto_source_code_config.multi_module_java is used
@pytest.mark.django_db
def test_matcher_test_platform_java_threads() -> None:
data = {
"platform": "java",
Expand Down
8 changes: 0 additions & 8 deletions tests/sentry/utils/test_event_frames.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import unittest

import pytest

from sentry.testutils.cases import TestCase
from sentry.utils.event_frames import (
EventFrame,
Expand Down Expand Up @@ -78,8 +76,6 @@ def test_platform_other(self) -> None:
def test_platform_sdk_name_not_supported(self) -> None:
assert not munged_filename_and_frames("javascript", [], "munged", "sdk.other")

# Only necessary while auto_source_code_config.multi_module_java is used
@pytest.mark.django_db
def test_supported_platform_sdk_name_not_required(self) -> None:
frames = [
{
Expand All @@ -92,8 +88,6 @@ def test_supported_platform_sdk_name_not_required(self) -> None:


class JavaFilenameMungingTestCase(unittest.TestCase):
# Only necessary while auto_source_code_config.multi_module_java is used
@pytest.mark.django_db
def test_platform_java(self) -> None:
frames = [
{
Expand Down Expand Up @@ -146,8 +140,6 @@ def test_platform_java_do_not_follow_java_package_naming_convention_does_not_rai
munged = munged_filename_and_frames("java", [frame])
assert munged is None

# Only necessary while auto_source_code_config.multi_module_java is used
@pytest.mark.django_db
def test_platform_android_kotlin(self) -> None:
exception_frames = [
{
Expand Down
Loading