Skip to main content

Local variable values in stack traces

"This stack trace would be so much easier to debug if I knew what the value of that variable was" - said us, many many times. We finally scratched our own itch and built this into Rollbar.

It's really awesome. Take for example a bug I ran into with our new deploy emails feature:

"Hmmm, sure would be nice if I knew which variable was None--is it prev_deploy or deploy?" In the past, I would've had to reproduce locally, or add an additional rollbar.report_message() to log each variable in production. But now I can just press "locals" for the stack frame and see it instantly:

"OK, it's prev_deploy." That was all I needed: prev_deploy will be None when deploy is the very first deploy in this project. Easy two-line fix. Time taken from opening the Rollbar notification to committing the fix: 2 minutes. Rollbarred!

How it works

We've implemented this in Python (pyrollbar), and are actively exploring other languages. Ruby and PHP are looking promising. Here's how it works in Python.

When this feature is enabled and an exception is reported, we use the inspect module to collect:

  • all stack frames: names and values of all variables that are function arguments
  • in-project stack frames: names and values of all local variables

There are two main edge cases to deal with:

  1. The variable could contain sensitive data. To deal with this, we use the same scrub_fields configuration used for scrubbing request data. If the variable name matches one of the field names to be scrubbed, the variable's value will be scrubbed. (Like access_token in the screenshot above.)
  2. The variable could contain a circular reference, be extremely large, or otherwise hard to serialize. To deal with this, we use the repr module to safely convert the value to a string of reasonable length. We've been using this internally now in production for the past two weeks without issue.

How to Enable

If you're using Python, simply update to pyrollbar 0.8.0 or greater. Local variables are on by default; see the docs for the full config reference.

If you're using Erlang, you're in luck - erollbar already sends argument values. Check its docs for details.

Want this in a different language? Let us know -- email or open an issue on the GitHub repo for the appropriate Rollbar library.

Don't use Rollbar yet? Sign up for a free account, follow the setup instructions, and you'll be debugging production in power mode in no time.