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.1"

Usage

Require failbot_rails the very top of config/application.rb right after loading rails/all:

require File.expand_path('../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.

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: