Skip to content

ref(derive_code_mappings): Process frames instead of file paths #85174

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 5 commits into from
Feb 14, 2025

Conversation

armenzg
Copy link
Member

@armenzg armenzg commented Feb 13, 2025

For some languages (e.g. Java) we're going to process all frames, thus, we need to pass around more than the filenames.

For some languages (e.g. Java) we're going to process all frames, thus, we need to pass around more than the filenames.
@armenzg armenzg self-assigned this Feb 13, 2025
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 13, 2025
@@ -48,20 +49,22 @@ class UnsupportedFrameFilename(Exception):

def derive_code_mappings(
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 the function called by the endpoint. At a later point, we will have to pass more than just the filename so we can support
image

def __init__(self, frame_file_path: str) -> None:
def __init__(self, frame: Mapping[str, Any]) -> None:
# XXX: In the next PR, we will use more than just the filename
frame_file_path = frame["filename"]
Copy link
Member Author

Choose a reason for hiding this comment

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

In the PR for Java, we will use abs_path and module.

@@ -187,22 +190,24 @@ def list_file_matches(self, frame_filename: FrameFilename) -> list[dict[str, str
)
return file_matches

def _stacktrace_buckets(self, stacktraces: list[str]) -> dict[str, list[FrameFilename]]:
def _stacktrace_buckets(
self, frames: Sequence[Mapping[str, Any]]
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 along we had been passing the frames but I mislabeled the variable.

@@ -11,3 +11,5 @@
]
# These languages will run as dry-run mode by default
DRY_RUN_PLATFORMS: list[str] = []
# Some languages will also process system frames
PROCESS_ALL_FRAMES: list[str] = []
Copy link
Member Author

@armenzg armenzg Feb 13, 2025

Choose a reason for hiding this comment

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

We may one day do this for all platforms, however, for now, we will keep it to a short list.

if frame is None:
continue
if platform in PROCESS_ALL_FRAMES:
frames_to_process.append(frame)
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 the functional change to this function.

exceptions = get_path(data, "exception", "values", filter=True)
if exceptions:
return [e["stacktrace"] for e in exceptions if get_path(e, "stacktrace", "frames")]

stacktrace = data.get("stacktrace")
if stacktrace and stacktrace.get("frames"):
logger.warning("Investigate if we use this code path in production.")
Copy link
Member Author

Choose a reason for hiding this comment

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

The only reason I believe we need this block is because of the way I wrote the tests. If this error doesn't happen in production I will remove it.

Copy link
Member

Choose a reason for hiding this comment

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

totally a preference thing, but I'd rather send an info event to Sentry here instead of a gcp log.

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 me as well! logger.warning() captures a message in Sentry with a level of warning 👍🏻

@@ -47,14 +47,17 @@ def get(self, request: Request, organization: Organization) -> Response:
:param string stacktraceFilename:
:auth: required
"""
# XXX: Evaluate what else does the UI send us
Copy link
Member Author

Choose a reason for hiding this comment

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

I have added a task so I don't forget to check if "Set up code mappings" works for Java.

def _stacktrace_with_frames(frames: list[dict[str, Any]]) -> Stacktrace:
return {"stacktrace": {"frames": frames}}
def _exception_with_stacktrace(frames: list[dict[str, Any]]) -> dict[str, Any]:
return {"exception": {"values": [{"stacktrace": {"frames": frames}}]}}
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 data structure change is what I refer to in this comment:
image

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 functional changes in this test file besides data structure changes.

@armenzg armenzg requested a review from MichaelSun48 February 13, 2025 18:21
@armenzg armenzg marked this pull request as ready for review February 13, 2025 18:21
@armenzg armenzg requested a review from a team as a code owner February 13, 2025 18:21
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 98.52941% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ntry/issues/auto_source_code_config/stacktraces.py 92.85% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #85174       +/-   ##
===========================================
+ Coverage   46.25%   87.98%   +41.73%     
===========================================
  Files        9614     9624       +10     
  Lines      542907   543473      +566     
  Branches    21042    21029       -13     
===========================================
+ Hits       251112   478169   +227057     
+ Misses     291489    65000   -226489     
+ Partials      306      304        -2     

def get_frames_to_process(
data: NodeData | dict[str, Any], platform: str | None = None
) -> list[dict[str, Any]]:
"""It flattens all processableframes from the event's data."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""It flattens all processableframes from the event's data."""
"""It flattens all processable frames from the event's data."""

exceptions = get_path(data, "exception", "values", filter=True)
if exceptions:
return [e["stacktrace"] for e in exceptions if get_path(e, "stacktrace", "frames")]

stacktrace = data.get("stacktrace")
if stacktrace and stacktrace.get("frames"):
logger.warning("Investigate if we use this code path in production.")
Copy link
Member

Choose a reason for hiding this comment

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

totally a preference thing, but I'd rather send an info event to Sentry here instead of a gcp log.

@armenzg armenzg merged commit 3290371 into master Feb 14, 2025
49 checks passed
@armenzg armenzg deleted the ref/process_frames/auto_source/armenzg branch February 14, 2025 12:29
Copy link

sentry-io bot commented Feb 14, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ AttributeError: 'NoneType' object has no attribute 'get' sentry.tasks.post_process.post_process_group View Issue
  • ‼️ UnsupportedFrameFilename: This path is not supported. /api/0/organizations/{organization_id_or_slug}/... View Issue
  • ‼️ UnsupportedFrameFilename: It needs an extension. /api/0/organizations/{organization_id_or_slug}/... View Issue

Did you find this useful? React with a 👍 or 👎

@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants