-
-
Notifications
You must be signed in to change notification settings - Fork 513
Implement local variable capture #7
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
Comments
Some quick benchmarking per-raise
|
I wonder if the code here could be a guide for implementing this: https://github.com/ko1/pretty_backtrace |
The better_errors gem also gets local vars, so could be used as a guide as well: https://github.com/charliesome/better_errors |
@thedrow unfamiliar with TracePoint (will google), but if you (or anyone interested) is around RailsConf would love to chat about how we make this a reality. |
Quick skim of TracePoint looks like its normal eval tracing which is far too expensive generally for what we'd want. I think a first pass would be to optionally support binding_of_caller. This would, for example, allow you to at least enable it in staging environments. |
I'm looking into this now as it's sort of our last "big feature" that we're missing in the Ruby client. Here's what I've decided:
|
@nateberkopec The "do not use in prod" is not (just) because of perf, binding-of-caller is effectively manually parsing the Ruby stack and if there is anything unexpected it's almost a guaranteed segfault. |
Got it. Can you give me an idea of what sort of circumstances that could happen under? |
That's harder to answer, usually these days it would just be new versions of Ruby but in the days of REE and whatnot, there were often patches floating around that would sometimes re-arrange the stack frame. |
OK, good to know. It looks like most of the segfaults surrounding binding_of_caller's approach have been solved since 1.9.3, but this does seem like a "high-danger" area where even raising in the wrong place can cause a segfault. So we may have to put it behind a config flag just for safety's sake. |
Yeah, on the plus side I don't think there are any runtime perf problems with BoC so the only thing it would slow down is the actual error reporting. |
Any progress on this? |
Every time I look at it I don't like the performance impact, and there's still not really a good, stable API for it. Not seeing this being implemented in the near future. |
🏓 Any chance of this implemented maybe as an opt-in feature? |
I've been using Sentry with Python projects for years and getting the values of local variables logged is one of my favorite features. The stack trace is useful, but frequently knowing what the actual state was at the time is critical to actually solving an issue quickly. I've got a few Ruby projects using Sentry as well now and while still useful for other reasons, it is significantly less useful than it is on my Python projects. |
Does anyone happen to know if the performance impact of is on all code, or only on I was thinking of hacking in a version of this to my code if it's just exception handling. |
@coffenbacher I've done a similar feature in my gem. The differences are:
And based on the benchmark result, I wouldn't recommend anyone running similar patches on production. Because many libraries or even your own code might use raise/rescue as a flow control mechanism. This means it could still significantly slow your app down even though you don't see any exceptions raised. You can also install my gem and set Bundler.require(*Rails.groups)
PowerTrace.replace_backtrace = true # need to be placed after bundler require in your |
@mecampbellsoup it's available on master and you can try it whenever you want to 😄 I've activated in my work project for 2 weeks and haven't seen any issue. |
Ah okay so this will be included in |
yeah it'll be included in |
@st0012 can we close this issue now? feature seems to be stable. |
Hmm not really because:
I'm still not sure how to resolve the restriction as it'll require more exploration on alternatives. |
I seem to be no longer getting local captures with this config:
Running Ruby 3.1.2 and |
@mecampbellsoup I can still see local variables captured though. Can you open a new issue with reproduction steps? Thx |
I am also not seeing local variables getting captured (in Rails) using a similar config to @mecampbellsoup. Rails 7.0.3, Ruby 3.1.2, and the latest
EDIT: It appears that I am not getting variables when making HTTP requests (using Faraday). I.e. I make a POST request with a payload that raises a @st0012 using your a = 1 b = 0 trick DID work for me, and I saw a and b get captured. But I haven't seen it work for any real production errors (Mainly Faraday errors) |
@RyanJWolfe could you give some Faraday request code so we can try to repro? |
The config is now |
I can't make this work. Both with include_local_variables and capture_exception_frame_locals. |
@pbassut please give sample code |
On 1.9.2 and 1.9.3 this can be done easily using the binding_of_caller gem.
Example monkey patch:
On 1.8.7 this could be possibly be done using the continuation tracing hack outlined in http://rubychallenger.blogspot.com/2011/07/caller-binding.html
The text was updated successfully, but these errors were encountered: