failbot_rails
Configures a Rails application to report exceptions to Haystack using the Failbot library.
Installation
Add it to the app's Gemfile manifest. The gem is publicly available but keep this repository private.
gem "failbot_rails", "~>0.3.4"
Usage
Require failbot_rails
the very top of config/application.rb
right after
loading rails/all
:
require File.('../boot', __FILE__)
require 'rails/all'
# report exceptions to Haystack using Failbot
require "failbot_rails"
FailbotRails.setup("my_app")
Every library, script or unicorn that loads the Rails environment are now setup to automatically report all exceptions to Haystack.
ENV Vars
In order for your exceptions to reach Haystack, you'll need to inform your
application of how to do that. Set these ENV
vars on your application in
production.
Heroku
To use failbot with heroku applications, the application needs the following environment variables set:
FAILBOT_BACKEND
FAILBOT_HAYSTACK_URL
FAILBOT_BACKEND
should always be set to http
. FAILBOT_HAYSTACK_URL
should be set to the value of FAILBOT_HAYSTACK_URL
of https://github.com/github/puppet/blob/master/modules/github/files/home/deploy/.rbexec/_failbot.rb.
Most versions of Failbot expect FAILBOT_BACKEND
to always be present. Try adding this line above require 'failbot'
to ensure that if FAILBOT_BACKEND
isn't configured, it will fall back to memory
:
ENV["FAILBOT_BACKEND"] ||= "memory"
EC2
Apps hosted on EC2 are managed by puppet. Puppet has these ENV vars already. You don't have to worry about them.
failbot_context
The exception context is automatically populated with request metadata including
the URL, method, params, etc. It can be augmented by defining afailbot_context
method on ApplicationController
:
def failbot_context
{:repo => current_repository.name_with_owner}
end
failbot(exception, context={})
Use the failbot
helper anywhere in controllers, views or helpers to manually
rescue and report an exception. Often used in "graceful degradation" situations.
Often risky and error prone but sometimes worth it. Consider carefully before
using.
def load_tree
current_repository.tree(params[:tree])
rescue TreeCorruptError
failbot($!)
nil
end
Contributing
The failbot_rails project follows the open source contribution model and is maintained by @sr. Open a pull request and wait for a :+1: