-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
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.
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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:
sentry/src/sentry/issues/auto_source_code_config/code_mapping.py
Lines 578 to 614 in c86f666
# 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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
Codecov ReportAttention: Patch coverage is ✅ All tests successful. No failed tests found.
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 |
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).
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).
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.