Skip to content
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

feat(code-mappings): Add support for stacktrace frames with backslashes for automatic code mappings #68845

Merged
merged 4 commits into from
Apr 16, 2024

Conversation

MichaelSun48
Copy link
Member

@MichaelSun48 MichaelSun48 commented Apr 12, 2024

This PR updates the existing code mapping logic to support stack traces whose filepaths contained backslashes instead of forward slashes. This effectively adds automatic code mapping support for issues derived from Windows machines (for the existing supported languages).

I've made the choice to save stack roots in the code mappings using whichever slash delimiter that the original stack path used. For example, if we have the following stack path and source:

  • Stack Path = "D:\Users\code\sentry\models\release.py"
  • Source path = "src/sentry/models/release.py"

Then the roots generated will be:

  • Stack Root = "D:\Users\code\" (note that this source root still uses backslashes instead of forward slashes)
  • Source Root = "src/"

This should be less confusing to the end user since we explicitly say we are going to replace the stack_root in the stack_path with the source_root to get the source_path. It might be confusing if the stack_root's slash-delimiter was not the same as that in the stack_path.

This also means that the previous logic to apply code mappings to a given frame to generate a stacktrace link needed to be updated so that the source path generated would only include slashes (since this path is used in a github URL, which only uses forward slashes).

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Apr 12, 2024
Copy link

codecov bot commented Apr 12, 2024

Codecov Report

Attention: Patch coverage is 94.73684% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 79.72%. Comparing base (9c99a10) to head (79d247d).
Report is 160 commits behind head on master.

❗ Current head 79d247d differs from pull request most recent head 41692e5. Consider uploading reports for the commit 41692e5 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #68845      +/-   ##
==========================================
- Coverage   79.72%   79.72%   -0.01%     
==========================================
  Files        6422     6422              
  Lines      284675   284697      +22     
  Branches    49043    49045       +2     
==========================================
+ Hits       226963   226978      +15     
- Misses      57346    57353       +7     
  Partials      366      366              
Files Coverage Δ
src/sentry/integrations/utils/code_mapping.py 91.28% <94.73%> (-0.02%) ⬇️

... and 30 files with indirect coverage changes

@MichaelSun48 MichaelSun48 removed the WIP label Apr 15, 2024
@MichaelSun48 MichaelSun48 marked this pull request as ready for review April 15, 2024 22:33
@MichaelSun48 MichaelSun48 requested review from a team as code owners April 15, 2024 22:33
@JoshFerge JoshFerge requested a review from bruno-garcia April 15, 2024 22:33
@@ -61,15 +61,19 @@ class UnsupportedFrameFilename(Exception):
class FrameFilename:
def __init__(self, frame_file_path: str) -> None:
self.raw_path = frame_file_path
if frame_file_path[0] == "/":
is_windows_path = False
if "\\" in frame_file_path:
Copy link
Member

Choose a reason for hiding this comment

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

can this conflict with the escape character on Linux? e.g: \ as an escape for a space in the path? or is that just a shell thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is an interesting edge case! I am admittedly not very knowledgable on Linux or Shell, but a quick search tells me that this seems like more of a shell thing than a Linux thing. I'm less sure about the probability of a backslash escape character being used in a the file path of a stack trace, though the safety checks should catch these and ensure it doesn't result in any faulty code mappings. I'll periodically check the logs generated by those safety checks to see how often this edge case actually occurs and what the best way to resolve them is.

@MichaelSun48 MichaelSun48 requested a review from armenzg April 16, 2024 15:56
Comment on lines +389 to +392
stack_root = code_mapping.stack_root
if "\\" in code_mapping.stack_root:
stack_root = code_mapping.stack_root.replace("\\", "/")

Copy link
Member Author

Choose a reason for hiding this comment

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

This function (convert_stacktrace_frame_path_to_source_path) contains the logic that applies a code mapping to a given stack trace and returns the source path to the GH file.

This needed to be augmented to normalize for backslashes in the stack root, as described in the PR description

Copy link
Member

@armenzg armenzg left a comment

Choose a reason for hiding this comment

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

Fantastic job! 🎉
Just a minor change for one of the cases.

@MichaelSun48 MichaelSun48 changed the title feat(code-mappings): Add support for stacktrace frames with backslashe for automatic code mappings feat(code-mappings): Add support for stacktrace frames with backslashes for automatic code mappings Apr 16, 2024
@MichaelSun48 MichaelSun48 merged commit 4ed24e4 into master Apr 16, 2024
49 checks passed
@MichaelSun48 MichaelSun48 deleted the michaelsun/autoCodeMappingBackSlashSupport branch April 16, 2024 21:18
@MichaelSun48 MichaelSun48 added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Apr 17, 2024
@getsentry-bot
Copy link
Contributor

PR reverted: f186916

getsentry-bot added a commit that referenced this pull request Apr 17, 2024
…ackslashes for automatic code mappings (#68845)"

This reverts commit 4ed24e4.

Co-authored-by: MichaelSun48 <[email protected]>
@MichaelSun48 MichaelSun48 restored the michaelsun/autoCodeMappingBackSlashSupport branch May 2, 2024 18:48
MichaelSun48 added a commit that referenced this pull request May 2, 2024
…s with backslashes for automatic code mappings (#68845)""

This reverts commit f186916.
@MichaelSun48 MichaelSun48 deleted the michaelsun/autoCodeMappingBackSlashSupport branch May 2, 2024 19:13
MichaelSun48 added a commit that referenced this pull request May 2, 2024
…s with backslashes for automatic code mappings (#70164)

This PR un-reverts (re-reverts 🤔) [this
PR](#68845), which adds
automatic code mapping support for events with backslashes in the file
path. This PR was reverted out of an abundance of caution when the
`derive_code_mappings` task was killing memcache in s4s during the
response to #inc-716. This occurred because:
* The resolution to #inc-716 involved opening the floodgates to a
massive amount of backlogged events that needed to be processed
* `derive_code_mappings` pings the cache twice per event to ensure that
we only process one event per project per hour, and with no duplicate
issues per 24 hours.
* A little bit out of my wheelhouse, but s4s's memcache infrastructure
is significantly less robust than SaaS

After having a conversation with @beezz, we determined that this would
be highly unlikely to occur in SaaS (and there would be much bigger
problems in that scenario), even given the higher traffic we'd expect to
see in this task as a result of allowing more kinds of events to be
supported for automatic code mappings.
@github-actions github-actions bot locked and limited conversation to collaborators May 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants