Blog |

Improved ruby error reporting with our latest gem updates

Improved ruby error reporting with our latest gem updates
Table of Contents

Recently, we released version 2.13.0 of the rollbar-gem. This update is full of new features and some minor bug fixes. The full release notes can be found here, Release 2.13.0. Here are a few of the highlights in this update:

1. Allow overriding configuration

Many customers have asked to implement a way to override the default configuration for a specific block of code. Some of them use the same process to send reports to our API for different projects, some need to change the environment, and others want to use one async handler for a single block of code (or none at all).

So, we've added a new method called Rollbar.with_config to do this. It receives a Hash object with the configuration overrides you want to use for the given block. The configuration options can be found at Configuration. The Hash passed to with_config should be formatted like {environment: 'specific-environment'}. For example:

Rollbar.with_config(use_async: false) do
    # do work that may crash
  rescue => e

This method looks similar to Rollbar.scoped, and Rollbar.with_config uses it internally. Now Rollbar.scoped can receive a second argument with the configuration overrides for the given block of code. So if you need to set a new payload scope and new config for a code block, you can write:

scope = {context: 'foo'}
new_config = {framework: 'Sinatra'}

Rollbar.scoped(scope, new_config) do
    # do work that may crash
  rescue => e

In the example above, we are defining a new payload scope and overriding the framework configuration for the reported errors inside the given block.

2. Code and context

The data we send for each frame in a backtrace is the filename, code line number, and the method name. In the occurrence detail you can see the formatted backtrace showing that data.

However, Rollbar can give you more detailed information about the line of code for each frame. In fact, we can display the exact text for each line of code in the backtrace. Previously, the gem wasn't sending this information, so we've added it as a feature to this new release. You can configure whether or not to send the extra data per frame, send it only for lines of code related to your project files, or send it for all the backtrace lines. The new configuration option is send_extra_frame_data and can have the values :none, :app or :all. Example:

Rollbar.configure do |config|
  config.send_extra_frame_data = :all

3. Async with Resque

We've integrated the implementation for the Resque async handler from resque-rollbar in the gem, so you don't have to install the resque-rollbar gem anymore. Other async handlers were already available in the gem, such as DelayedJob, GirlFriday, Sidekiq, SuckerPunch, or the basic threaded one. We also wanted to have Resque in the gem, since we know it's used by many of our customers.

4. Content-Type and Content-Length

When debugging errors, it's important have as much useful information as possible, and we were missing the headers Content-Type and Content-Length. Now you'll see them in your occurrence details, so it will be easier to identify common errors with empty JSON bodies or wrong content types.

5. GET, POST, and JSON body in the right places

When pushing the request data into our API we were merging all the GET, POST, and JSON body parameters, and (if defined) Rails route parameters into the params attribute. We implemented it this way so that in a Rails controller you'd have everything merged into the params value. However, we wanted to separate them so it will be easier to find the correct data and identify what exactly is in the GET, POST, JSON body, or route params. Now, you'll find all that data is separated out in the occurrence details.

6. Bug fixes

We've pushed a few bug fixes for the gem, some of which were reported by our customers. Thank you to everyone who reported bugs! Some important bug fixes:

  • Fix DelayedJob serialization on some backends
  • Unable to send Rake reports at some scenarios
  • Validation reports with ActiveModel objects are fixed

I hope you take full advantage of the updates to the ruby gem. Please feel free to make pull requests, if there's anything you feel we could do better!

If you haven’t already, signup for a 14-day free trial of Rollbar and let us help you
defeat annoying ruby errors in your applications. 🙂

"Rollbar allows us to go from alerting to impact analysis and resolution in a matter of minutes. Without it we would be flying blind."

Error Monitoring

Start continuously improving your code today.

Get Started Shape