Skip to content

fix(stacktrace-link): Use new Java logic #90415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Apr 25, 2025

The stacktrace-link endpoint uses the original munging logic, which has a bug.

This change switches to the new logic and is gated behind a feature flag.

The stacktrace-link endpoint uses the original munging logic which has a bug.

This change switches to the new logic and its gated behind a feature flag.
@armenzg armenzg requested a review from MichaelSun48 April 25, 2025 19:27
@armenzg armenzg self-assigned this Apr 25, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 25, 2025
@@ -153,7 +153,7 @@ def get(self, request: Request, project: Project) -> Response:
scope = Scope.get_isolation_scope()

set_top_tags(scope, project, ctx, len(configs) > 0)
result = get_stacktrace_config(configs, ctx)
result = get_stacktrace_config(configs, ctx, project.organization)
Copy link
Member

Choose a reason for hiding this comment

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

is it possible for a project to not have an organization?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, it's not.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha, small nit — no need for the Organization | None types right?

Copy link
Member Author

Choose a reason for hiding this comment

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

@MichaelSun48 there's another for the function in commit_context, thus, made it optional.

I will patch it up in the next PR (I tried to focus the test changes).

@@ -386,6 +387,7 @@ def convert_stacktrace_frame_path_to_source_path(
code_mapping: RepositoryProjectPathConfig,
platform: str | None,
sdk_name: str | None,
organization: Organization | None = None,
Copy link
Member Author

Choose a reason for hiding this comment

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

Once we are satisfied with the new feature, we won't need to pass the organization.

)
if has_new_logic and platform == "java" and frame.module and frame.abs_path:
try:
_, stacktrace_path = get_path_from_module(frame.module, frame.abs_path)
Copy link
Member Author

Choose a reason for hiding this comment

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

get_path_from_module is the new logic we're using and closer to what symbolication does:

# Based on # https://github.com/getsentry/symbolicator/blob/450f1d6a8c346405454505ed9ca87e08a6ff34b7/crates/symbolicator-proguard/src/symbolication.rs#L450-L485
def get_path_from_module(module: str, abs_path: str) -> tuple[str, str]:
"""This attempts to generate a modified module and a real path from a Java module name and filename.
Returns a tuple of (stack_root, source_path).
"""
# An `abs_path` is valid if it contains a `.` and doesn't contain a `$`.
if "$" in abs_path or "." not in abs_path:
# Split the module at the first '$' character and take the part before it
# If there's no '$', use the entire module
file_path = module.split("$", 1)[0] if "$" in module else module
stack_root = module.rsplit(".", 1)[0].replace(".", "/") + "/"
return stack_root, file_path.replace(".", "/")
if "." not in module:
raise DoesNotFollowJavaPackageNamingConvention
# Gets rid of the class name
parts = module.rsplit(".", 1)[0].split(".")
dirpath = "/".join(parts)
# 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/
# 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
stack_root = "/".join(parts[:granularity]) + "/"
file_path = f"{dirpath}/{abs_path}"
return stack_root, file_path

(
"com.example.foo.BarImpl$invoke$bazFetch$2",
"Bar.kt", # Notice "Impl" is not included in the module above
"src/com/example/foo/BarImpl.kt", # This is incorrect; the new logic will fix this
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 will remove this test case once we have switched over to the new logic.

sdk_name="sentry.java.android",
organization=self.organization,
)
== "src/com/example/foo/Baz.java"
Copy link
Member Author

Choose a reason for hiding this comment

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

Notice that Impl is not included in the file path.

@armenzg armenzg marked this pull request as ready for review April 25, 2025 19:33
@armenzg armenzg requested review from a team as code owners April 25, 2025 19:33
Copy link

codecov bot commented Apr 25, 2025

Codecov Report

Attention: Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...try/issues/auto_source_code_config/code_mapping.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #90415   +/-   ##
=======================================
  Coverage   87.79%   87.79%           
=======================================
  Files       10280    10278    -2     
  Lines      579577   579644   +67     
  Branches    22677    22677           
=======================================
+ Hits       508813   508896   +83     
+ Misses      70325    70309   -16     
  Partials      439      439           

@armenzg armenzg merged commit af4f63c into master Apr 28, 2025
65 checks passed
@armenzg armenzg deleted the fix/abs_path_module/auto_config/armenzg branch April 28, 2025 11:11
armenzg added a commit that referenced this pull request Apr 28, 2025
In #90415, I added the correct logic to derive filenames for Java frames.

This allows commit_context to take advantages of it (it's behind a feature flag and we need to pass the `organization` value).
armenzg added a commit that referenced this pull request Apr 28, 2025
In #90415, I added the correct logic to derive filenames for Java
frames.

This allows commit_context to take advantage of it (it's behind a
feature flag and we need to pass the `organization` value).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants