Debugging Production Rails Apps with Rollbar

Notes


In this lesson we're going to learn how to debug our application in it's production environment. Rails has really great error messages when we're working in the development environment but we're unlikely to ever see them when our application is running in production. A great way to remedy this is using a third-party service called Rollbar.

Rollbar comes in the form of a gem and gives us some methods we can use to send errors or information to their website. Integrating it into our application is pretty easy. We just need to install the gem and sign up for the service.

To start, let's just head to the Rollbar website and sign up. After signing up we'll need to create a new project. After creating the project choose to integrate Rollbar into Rails and we will be presented with a list of instructions.

The first step in their instructions is to install the Rollbar gem.

gem 'rollbar'

followed by

bundle install

Next, Rollbar is working with our handy rails generate command to create most of the integration code for us.

rails generate rollbar

This command created your Rollbar config file. It's located in our application's root/config/initializers directory and simply named rollbar.rb. Once we have this file open we'll see that our access token's value is set using an environment variable. We need to add this to our .env file locally, but more importantly we need to set it on our Heroku server as well. Refer back to the AWS S3 storage lesson if you need a reminder on how to do it through the Heroku UI or try the command Rollbar gives to work with the Heroku CLI:

heroku config:add ROLLBAR_ACCESS_TOKEN=YOUR-ACCESS-TOKEN-HERE

We still need to include code in our application to tell Rollbar when to send this information but it is now possible to do so!

Happy coding!!!!