-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
fix(stacktrace-link): Only code mappings that match should affect the API response #41562
fix(stacktrace-link): Only code mappings that match should affect the API response #41562
Conversation
@@ -15,8 +15,9 @@ | |||
|
|||
|
|||
def get_link( | |||
config: RepositoryProjectPathConfig, filepath: str, default: str, version: Optional[str] = None | |||
) -> Tuple[Optional[str], Optional[str], Optional[str]]: | |||
config: RepositoryProjectPathConfig, filepath: str, version: Optional[str] = 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.
Using Any
instead of dict[str, str]
because some weird issue I was not able to figure out.
I can try again in the future.
|
||
# This is to support mobile languages with non-fully-qualified file pathing. | ||
# We attempt to 'munge' the proper source-relative filepath based on the stackframe data. | ||
def generate_mobile_frame(parameters: Any) -> Any: |
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.
I just moved the code from here into a function:
sentry/src/sentry/api/endpoints/project_stacktrace_link.py
Lines 67 to 76 in b0b214f
abs_path = request.GET.get("absPath") | |
module = request.GET.get("module") | |
package = request.GET.get("package") | |
frame = {} | |
if abs_path: | |
frame["abs_path"] = abs_path | |
if module: | |
frame["module"] = module | |
if package: | |
frame["package"] = package |
@@ -56,24 +109,21 @@ class ProjectStacktraceLinkEndpoint(ProjectEndpoint): | |||
""" | |||
|
|||
def get(self, request: Request, project) -> Response: | |||
# import pprint | |||
|
|||
# pprint.pp(request) |
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.
I will remove this in the following push.
@@ -85,69 +135,63 @@ def get(self, request: Request, project) -> Response: | |||
if i.has_feature(IntegrationFeatures.STACKTRACE_LINK) | |||
] | |||
|
|||
last_error = 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.
Not needed anymore.
|
||
link, attempted_url, error = get_link( | ||
config, munged_filename, config.default_branch, commit_id | ||
) |
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.
This whole block is now done above like this:
# For mobile we try a second time by munging the file path
if not result["sourceUrl"] and mobile_frame:
result = try_path_munging(filepath, mobile_frame, ctx)
last_error = get_link_error | ||
result["attemptedUrl"] = attempted_url | ||
if not result["sourceUrl"]: | ||
matched_code_mappings.append(current_config) |
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.
This will create a list of all code mappings that were attempted and its result.
@@ -15,27 +15,77 @@ | |||
|
|||
|
|||
def get_link( | |||
config: RepositoryProjectPathConfig, filepath: str, default: str, version: Optional[str] = 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.
config
contains the default branch. I'm reducing the signature.
return frame | ||
|
||
|
||
def try_path_munging( |
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.
This function comes from the main loop.
sentry/src/sentry/api/endpoints/project_stacktrace_link.py
Lines 114 to 130 in b0b214f
frame["filename"] = filepath | |
munged_frames = munged_filename_and_frames( | |
platform, [frame], "munged_filename", sdk_name=sdk_name | |
) | |
if munged_frames: | |
munged_frame: Mapping[str, Any] = munged_frames[1][0] | |
munged_filename = str(munged_frame.get("munged_filename")) | |
if munged_filename: | |
if not filepath.startswith( | |
config.stack_root | |
) and not munged_filename.startswith(config.stack_root): | |
last_error = "stack_root_mismatch" | |
continue | |
link, attempted_url, error = get_link( | |
config, munged_filename, config.default_branch, commit_id | |
) |
"platform": request.GET.get("platform"), | ||
"sdk_name": request.GET.get("sdkName"), | ||
} | ||
mobile_frame = generate_mobile_frame(request.GET) |
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.
Using mobile_frame
later in the code to decide if this is a mobile platform does not make sense. Either way, here we are.
with configure_scope() as scope: | ||
scope.set_tag("project.slug", project.slug) | ||
scope.set_tag("organization.slug", project.organization.slug) |
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.
These are two new tags.
@@ -116,10 +116,8 @@ def test_file_not_found_error(self): | |||
) | |||
assert response.data["config"] == self.expected_configurations(self.code_mapping1) | |||
assert not response.data["sourceUrl"] | |||
# XXX: This depends on what was the last attempted code mapping | |||
assert response.data["error"] == "stack_root_mismatch" | |||
assert response.data["error"] == "file_not_found" |
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.
In #41409 I added more than one code mapping and it showed that the error value would depend on the last attempted code mapping rather than the last one that matched.
This PR fixes the issue since the first code mapping matches the stack trace root and the source file is not found (as the original test was):
stack_root="usr/src/getsentry/", |
Changes: