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

fix: Trim long stacktraces #3795

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

szokeasaurusrex
Copy link
Member

Only process and send the first 300 stack frames for an error event. This prevents the SDK from causing the program to hang when the SDK captures an error with a very large number of stack frames. Relay anyways trims events to 250 stack frames, so it is pointless for us to process much beyond that number.

Fixes #2764

Only process and send the first 300 stack frames for an error event. This prevents the SDK from causing the program to hang when the SDK captures an error with a very large number of stack frames. Relay anyways [trims events to 250 stack frames](https://github.com/getsentry/relay/blob/aae36669414a1f7c6ef68d5226cb2e96a28f7667/relay-event-normalization/src/trimming.rs#L286), so it is pointless for us to process much beyond that number.

Fixes #2764
Copy link
Member Author

@szokeasaurusrex szokeasaurusrex left a comment

Choose a reason for hiding this comment

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

@jan-auer, is there any way we can or should indicate to Relay that we have trimmed the stacktrace? @Dav1dde was saying that this might be possible to do via the _meta field.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.32%. Comparing base (ec2d929) to head (df00c7d).

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3795      +/-   ##
==========================================
+ Coverage   84.30%   84.32%   +0.01%     
==========================================
  Files         137      137              
  Lines       14561    14564       +3     
  Branches     2460     2460              
==========================================
+ Hits        12276    12281       +5     
+ Misses       1528     1525       -3     
- Partials      757      758       +1     
Files with missing lines Coverage Δ
sentry_sdk/consts.py 99.52% <100.00%> (+<0.01%) ⬆️
sentry_sdk/utils.py 85.94% <100.00%> (+0.01%) ⬆️

... and 2 files with indirect coverage changes

@sl0thentr0py
Copy link
Member

please make sure that this is trimming from the correct side of the backtrace since there's a lot of weird reverses in the pipeline from SDK -> ingest -> final persisting

@szokeasaurusrex
Copy link
Member Author

@sl0thentr0py looks like actually this is trimming from the wrong end of the backtrace (the final calls will get trimmed, when in fact, they are probably the most interesting to the user). Thanks for the good catch!

The problem is that I don't think there is a straightforward way to iterate the stack trace in the reverse order. Iterating through the entire stack trace to get the last 300 (or other limit) entries, when the stack trace is very large, is not a good idea though, since the slowness causing #2764 seems to stem from the iteration.

So, perhaps we can set a larger stack trace limit (e.g. 1000 frames), and if this is exceeded, we would just drop the stack trace completely from the event? What do you think?

We should also perhaps confirm which end of the stack trace Relay is trimming. Likely we want to be doing the same thing as them.

@szokeasaurusrex szokeasaurusrex marked this pull request as draft November 18, 2024 17:36
@Dav1dde
Copy link
Member

Dav1dde commented Nov 18, 2024

We should also perhaps confirm which end of the stack trace Relay is trimming. Likely we want to be doing the same thing as them.

Relay is trimming not the end of the stracktrace but for recursions the middle on a best effort basis.

@jan-auer
Copy link
Member

jan-auer commented Nov 19, 2024

is there any way we can or should indicate to Relay that we have trimmed the stacktrace?

Yes, this can be done through the len field on the corresponding meta entry for the frames field in the stack trace. For example, in an exception's frames, this would be set on meta for exception.values[0].stacktrace.frames.

However, this information will not be shown in the UI at the moment. If you want to display this to a user, this needs to be added to the issue details UI.

Edit: For the time being, I'd suggest not to do any of this. Since the UI won't show trimmed stack traces and the future of using _meta is uncertain, let's try to go without that additional information. If we get a strong indication from users that such meta data is needed, let's please revisit this.

@jan-auer jan-auer removed their request for review November 19, 2024 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SDK stuck in processing RecursionError:maximum recursion depth exceeded events
4 participants