Support recording exception frame's local variables for requests #1580
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
This PR introduces a new feature to capture local variables when an exception is raised. For example, given this script:
The captured exception will contain the value of local variable
a
andb
.Here are some screenshots:
From this SDK's demo application
From my company's application with a real error
This feature needs to be activated with the new
capture_exception_frame_locals
config option:So if you don't want to use it, it won't affect your application.
Reason
It's the dream, isn't it 😉
Limitations & Caveats
Sentry::CaptureExceptions
middleware. Background job support will come later.Full
stacktrace view.Rails.application.config.filter_parameters
.Performance Impact
TL;DR:
Benchmark (with Ruby 2.7.4)
When the local-capturing
TracePoint
is enable, exception handling slows down significantly.However, our applications don't just raise exceptions and do nothing. So let's simulate some extra timespent on other stuff with sleep (just 50 ms):
Since Ruby's exception raising/rescuing are pretty fast, the extra overhead added by
TracePoint
isn't even observable in this case.Future Development
If this approach is proved working, we can enhance it in 2 directions:
The 2nd enhancement may be the most-desirable feature to add. However, its overhead may be significant because the SDK will need to walk through every frame for collecting local variables, and do that for every exception raised. So it's possible that we need to introduce it with extra configurations to reduce the overhead (e.g. only capture certain number of frames or certain exceptions).