github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

thoughtbot / hoptoad_notifier

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 359
    • 57
  • Source
  • Commits
  • Network (57)
  • Downloads (29)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (4)
    • 470-unmask-actionview-template
    • changeling
    • master ✓
    • rack
  • Tags (29)
    • v2.1.3
    • v2.1.2
    • v2.1.1
    • v2.1.0
    • v2.0.19
    • v2.0.18
    • v2.0.17
    • v2.0.16
    • v2.0.15
    • v2.0.14
    • v2.0.13
    • v2.0.12
    • v2.0.11
    • v2.0.10
    • v2.0.9
    • v2.0.8
    • v2.0.7
    • v2.0.6
    • v2.0.5
    • v2.0.4
    • v2.0.3
    • v2.0.2
    • v2.0.1
    • v2.0.0
    • v1.2.4
    • v1.2.3
    • v1.2.2
    • v1.2.1
    • v1.2.0
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Reports exceptions to Hoptoad — Read more

  cancel

http://www.hoptoadapp.com/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Typesetting in README.rdoc 
Jason Morrison (author)
Tue Feb 02 11:21:58 -0800 2010
commit  1be3591f434f54e0933503ad47370ba88a948302
tree    f239c2f705f55ac0e8c3834a38a2ec8892bbf73a
parent  4d8e880e70e4bc720928272c1b0f8b762aaa8381
hoptoad_notifier /
name age
history
message
file .gitignore Tue Jan 19 13:09:26 -0800 2010 Changed rake tasks to be included instead of co... [jferris]
file .yardopts Thu Nov 05 08:14:16 -0800 2009 Removing INSTALL and making sure the testing an... [qrush]
file INSTALL Tue Dec 01 13:45:25 -0800 2009 Added INSTALL to display config info when the p... [jyurek]
file MIT-LICENSE Wed Mar 04 12:31:31 -0800 2009 Added MIT license [tsaleh]
file README.rdoc Tue Feb 02 11:21:58 -0800 2010 Typesetting in README.rdoc [Jason Morrison]
file Rakefile Thu Jan 28 12:23:44 -0800 2010 Added integration/readme coverage of Sinatra apps [jferris]
file SUPPORTED_RAILS_VERSIONS Wed Jan 20 12:17:41 -0800 2010 Notifier does not support 2.3.3, does support 2... [Jason Morrison]
file TESTING.rdoc Thu Nov 05 08:14:16 -0800 2009 Removing INSTALL and making sure the testing an... [qrush]
directory features/ Thu Jan 28 13:47:20 -0800 2010 Require rack in tests for older versions of Rai... [jferris]
directory generators/ Wed Jan 27 12:05:50 -0800 2010 Updating the uninstall instructions to use scri... [qrush]
file ginger_scenarios.rb Fri Jan 15 08:41:04 -0800 2010 Add a Ginger scenario to verify the notifier wo... [Jason Morrison]
file install.rb Wed Jul 30 13:56:37 -0700 2008 Made some quick mods for 1.2.6 [jyurek]
directory lib/ Thu Jan 28 12:23:44 -0800 2010 Added docs to HoptoadNotifier::Rack [jferris]
directory rails/ Tue Jan 19 13:09:25 -0800 2010 Added a test for the installation process [jferris]
directory script/ Thu Nov 05 08:12:10 -0800 2009 Fixed version numbers and other project info no... [Joe Ferris]
directory test/ Thu Jan 28 13:47:20 -0800 2010 Require rack in tests for older versions of Rai... [jferris]
file things-the-generator-must-do Tue Jan 19 13:02:10 -0800 2010 Change wording to refer to the gem instead of p... [mike-burns]
directory vendor/ Wed Mar 18 11:38:39 -0700 2009 Vendoring ginger and adding rake ginger task [qrush]
README.rdoc

HoptoadNotifier

This is the notifier gem for integrating apps with Hoptoad.

When an uncaught exception occurs, HoptoadNotifier will POST the relevant data to the Hoptoad server specified in your environment.

Help

  • IRC
  • mailing list

Rails Installation

Remove exception_notifier

in your ApplicationController, REMOVE this line:

  include ExceptionNotifiable

In your config/environment* files, remove all references to ExceptionNotifier

Remove the vendor/plugins/exception_notifier directory.

Remove hoptoad_notifier plugin

Remove the vendor/plugins/hoptoad_notifier directory before installing the gem, or run:

  script/plugin remove hoptoad_notifier

Rails 2.x

Add the hoptoad_notifier gem to your app. In config/environment.rb:

  config.gem 'hoptoad_notifier'

Then from your project’s RAILS_ROOT, run:

  rake gems:install
  script/generate hoptoad --api-key your_key_here

Once installed, you should vendor the hoptoad_notifier gem.

  rake gems:unpack GEM=hoptoad_notifier

As always, if you choose not to vendor the hoptoad_notifier gem, make sure every server you deploy to has the gem installed or your application won’t start.

Rails 1.2.6

Install the hoptoad_notifier gem:

  gem install hoptoad_notifier

Once installed, you should vendor the hoptoad_notifier gem:

  mkdir vendor/gems
  cd vendor/gems
  gem unpack hoptoad_notifier

And then add the following to the Rails::Initializer.run do |config| block in environment.rb so that the vendored gem is loaded.

  # Add the vendor/gems/*/lib directories to the LOAD_PATH
  config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))

Next add something like this at the bottom of your config/environment.rb:

  require 'hoptoad_notifier'
  require 'hoptoad_notifier/rails'
  HoptoadNotifier.configure do |config|
    config.api_key = 'your_key_here'
  end

You will also need to copy the hoptoad_notifier_tasks.rake file into your RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work:

  cp vendor/gems/hoptoad_notifier-2.1.3/generators/hoptoad/templates/hoptoad_notifier_tasks.rake lib/tasks

As always, if you choose not to vendor the hoptoad_notifier gem, make sure every server you deploy to has the gem installed or your application won’t start.

Testing it out

You can test that Hoptoad is working in your production environment by using this rake task (from RAILS_ROOT):

  rake hoptoad:test

If everything is configured properly, that task will send a notice to Hoptoad which will be visible immediately.

Rack

In order to use hoptoad_notifier in a non-Rails rack app, just load the hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack middleware:

  require 'rack'
  require 'hoptoad_notifier'

  HoptoadNotifier.configure do |config|
    config.api_key = 'my_api_key'
  end

  app = Rack::Builder.app do
    use HoptoadNotifier::Rack
    run lambda { |env| raise "Rack down" }
  end

Sinatra

Using hoptoad_notifier in a Sinatra app is just like a Rack app, but you have to disable Sinatra’s error rescuing functionality:

  require 'sinatra/base'
  require 'hoptoad_notifier'

  HoptoadNotifier.configure do |config|
    config.api_key = 'my_api_key'
  end

  class MyApp < Sinatra::Default
    use HoptoadNotifier::Rack
    enable :raise_errors

    get "/" do
      raise "Sinatra has left the building"
    end
  end

Usage

For the most part, Hoptoad works for itself. Once you’ve included the notifier in your ApplicationController (which is now done automatically by the gem), all errors will be rescued by the #rescue_action_in_public provided by the gem.

If you want to log arbitrary things which you’ve rescued yourself from a controller, you can do something like this:

  ...
  rescue => ex
    notify_hoptoad(ex)
    flash[:failure] = 'Encryptions could not be rerouted, try again.'
  end
  ...

The #notify_hoptoad call will send the notice over to Hoptoad for later analysis. While in your controllers you use the notify_hoptoad method, anywhere else in your code, use HoptoadNotifier.notify.

To perform custom error processing after Hoptoad has been notified, define the instance method #rescue_action_in_public_without_hoptoad(exception) in your controller.

Tracking deployments in Hoptoad

Paying Hoptoad plans support the ability to track deployments of your application in Hoptoad. By notifying Hoptoad of your application deployments, all errors are resolved when a deploy occurs, so that you’ll be notified again about any errors that reoccur after a deployment.

Additionally, it’s possible to review the errors in Hoptoad that occurred before and after a deploy.

When Hoptoad is installed as a gem, you need to add

  require 'hoptoad_notifier/capistrano'

to your deploy.rb

Going beyond exceptions

You can also pass a hash to notify_hoptoad method and store whatever you want, not just an exception. And you can also use it anywhere, not just in controllers:

  begin
    params = {
      # params that you pass to a method that can throw an exception
    }
    my_unpredicable_method(params)
  rescue => e
    HoptoadNotifier.notify(
      :error_class   => "Special Error",
      :error_message => "Special Error: #{e.message}",
      :parameters    => params
    )
  end

While in your controllers you use the notify_hoptoad method, anywhere else in your code, use HoptoadNotifier.notify. Hoptoad will get all the information about the error itself. As for a hash, these are the keys you should pass:

  • :error_class - Use this to group similar errors together. When Hoptoad catches an exception it sends the class name of that exception object.
  • :error_message - This is the title of the error you see in the errors list. For exceptions it is "#{exception.class.name}: #{exception.message}"
  • :parameters - While there are several ways to send additional data to Hoptoad, passing a Hash as :parameters as in the example above is the most common use case. When Hoptoad catches an exception in a controller, the actual HTTP client request parameters are sent using this key.

Hoptoad merges the hash you pass with these default options:

  {
    :api_key       => HoptoadNotifier.api_key,
    :error_message => 'Notification',
    :backtrace     => caller,
    :parameters    => {},
    :session       => {}
  }

You can override any of those parameters.

Filtering

You can specify a whitelist of errors, that Hoptoad will not report on. Use this feature when you are so apathetic to certain errors that you don’t want them even logged.

This filter will only be applied to automatic notifications, not manual notifications (when #notify is called directly).

Hoptoad ignores the following exceptions by default:

  ActiveRecord::RecordNotFound
  ActionController::RoutingError
  ActionController::InvalidAuthenticityToken
  ActionController::UnknownAction
  CGI::Session::CookieStore::TamperedWithCookie

To ignore errors in addition to those, specify their names in your Hoptoad configuration block.

  HoptoadNotifier.configure do |config|
    config.api_key      = '1234567890abcdef'
    config.ignore       << ActiveRecord::IgnoreThisError
  end

To ignore only certain errors (and override the defaults), use the #ignore_only attribute.

  HoptoadNotifier.configure do |config|
    config.api_key      = '1234567890abcdef'
    config.ignore_only  = [ActiveRecord::IgnoreThisError]
  end

To ignore certain user agents, add in the #ignore_user_agent attribute as a string or regexp:

  HoptoadNotifier.configure do |config|
    config.api_key      = '1234567890abcdef'
    config.ignore_user_agent  << /Ignored/
    config.ignore_user_agent << 'IgnoredUserAgent'
  end

To ignore exceptions based on other conditions, use #ignore_by_filter:

  HoptoadNotifier.configure do |config|
    config.api_key      = '1234567890abcdef'
    config.ignore_by_filter do |exception_data|
      true if exception_data[:error_class] == "RuntimeError"
    end
  end

To replace sensitive information sent to the Hoptoad service with [FILTERED] use #params_filters:

  HoptoadNotifier.configure do |config|
    config.api_key      = '1234567890abcdef'
    config.params_filters << "credit_card_number"
  end

Note that, when rescuing exceptions within an ActionController method, hoptoad_notifier will reuse filters specified by #filter_params_logging.

Testing

When you run your tests, you might notice that the Hoptoad service is recording notices generated using #notify when you don’t expect it to. You can use code like this in your test_helper.rb to redefine that method so those errors are not reported while running tests.

  module HoptoadNotifier
    def self.notify(thing)
      # do nothing.
    end
  end

Supported Rails versions

See SUPPORTED_RAILS_VERSIONS for a list of official supported versions of Rails.

Please open up a support ticket on Tender ( help.hoptoadapp.com ) if you’re using a version of Rails that is not listed above and the notifier is not working properly.

Thanks

Thanks to Eugene Bolshakov for the excellent write-up on GOING BEYOND EXCEPTIONS, which we have included above.

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server