Skip to content
This repository has been archived by the owner on May 12, 2023. It is now read-only.

Commit

Permalink
Upgrading hoptoad notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Nov 17, 2009
1 parent 097975b commit 7522f9f
Show file tree
Hide file tree
Showing 30 changed files with 2,479 additions and 1,272 deletions.
3 changes: 3 additions & 0 deletions vendor/plugins/hoptoad_notifier/.yardopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-
TESTING.rdoc
MIT-LICENSE
55 changes: 0 additions & 55 deletions vendor/plugins/hoptoad_notifier/INSTALL

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
HoptoadNotifier
===============
= HoptoadNotifier

This is the notifier plugin for integrating apps with Hoptoad.

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

INSTALLATION
------------
== Help

REMOVE EXCEPTION_NOTIFIER
* {IRC}[irc://irc.freenode.net/thoughtbot]
* {mailing list}[http://groups.google.com/group/hoptoad-notifier-dev]

In your ApplicationController, REMOVE this line:
== 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.

INSTALL HOPTOAD_NOTIFIER
=== Install hoptoad_notifier

From your project's RAILS_ROOT, run:
from your project's RAILS_ROOT, run:

script/plugin install git://github.com/thoughtbot/hoptoad_notifier.git

CONFIGURATION
=== Configuration

You should have something like this in config/initializers/hoptoad.rb.
you should have something like this in config/initializers/hoptoad.rb.

HoptoadNotifier.configure do |config|
config.api_key = '1234567890abcdef'
Expand All @@ -38,27 +41,30 @@ is *not* environment-specific. Hoptoad is smart enough to know what errors are
caused by what environments, so your staging errors don't get mixed in with
your production errors.)

After adding to your config/initializers like this you must restart your
server. This will not affect the rake task but it bears stating.

That should be it! Now all exceptions will be logged to Hoptoad where they can
be aggregated, filtered, sorted, analyzed, massaged, and searched. In previous
releases you had to include HoptoadNotifier::Catcher into your
ApplicationController, but the plugin takes care of that now.

** NOTE FOR RAILS 1.2.* USERS: **
You will need to copy the hoptoad_notifier_tasks.rake file into your
RAILS_ROOT/lib/tasks directory in order for the following to work:

You can test that hoptoad is working in your production environment by using
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
If everything is configured properly, that task will send a notice to Hoptoad
which will be visible immediately.

USAGE
-----
=== NOTE FOR RAILS 1.2.* USERS:

You will 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.

== Usage

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

Expand All @@ -72,13 +78,11 @@ controller, you can do something like this:
end
...

The #notify_hoptoad call will send the notice over to hoptoad for later
analysis.
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
-------------------------------
== 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,
Expand All @@ -88,51 +92,50 @@ Additionally, it's possible to review the errors in Hoptoad that occurred before

When Hoptoad is installed as a plugin this functionality is loaded automatically (if you have Capistrano version 2.0.0 or greater).

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

require 'hoptoad_notifier/recipes/hoptoad'

to your deploy.rb

GOING BEYOND EXCEPTIONS
-----------------------
== 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 = {
begin
params = {
# params that you pass to a method that can throw an exception
}
my_unpredicable_method(params)
my_unpredicable_method(params)
rescue => e
HoptoadNotifier.notify(
:error_class => "Special Error",
:error_message => "Special Error: #{e.message}",
:error_class => "Special Error",
:error_message => "Special Error: #{e.message}",
:request => { :params => 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}"
* :request – While there are several ways to send additional data to Hoptoad, passing a Hash with :params key as :request as in the example above is the most common use case. When Hoptoad catches an exception in a controller, the actual HTTP client request is being sent using this key.
* :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}"
* :request – While there are several ways to send additional data to Hoptoad, passing a Hash with :params key as :request as in the example above is the most common use case. When Hoptoad catches an exception in a controller, the actual HTTP client request is being sent using this key.

Hoptoad merges the hash you pass with these default options:

def default_notice_options
{
:api_key => HoptoadNotifier.api_key,
:error_message => 'Notification',
:backtrace => caller,
:request => {},
:session => {},
:environment => ENV.to_hash
}
{
:api_key => HoptoadNotifier.api_key,
:error_message => 'Notification',
:backtrace => caller,
:request => {},
:session => {}
}
end

You can override any of those parameters.

FILTERING
---------
== 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
Expand All @@ -142,9 +145,11 @@ 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
Expand Down Expand Up @@ -181,20 +186,19 @@ To ignore exceptions based on other conditions, use #ignore_by_filter:
end
end

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

HoptoadNotifier.configure do |config|
config.api_key = '1234567890abcdef'
config.environment_filters << "AWS_SECRET"
config.environment_filters << "EC2_PRIVATE_KEY"
config.environment_filters << "AWS_ACCESS"
config.environment_filters << "EC2_CERT"
config.params_filters << "credit_card_number"
end

TESTING
-------
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
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.
Expand All @@ -205,21 +209,20 @@ errors are not reported while running tests.
end
end

SUPPORTED RAILS VERSIONS
------------------------
== Supported rails versions

The notifier currently supports the following versions of Rails:
the notifier currently supports the following versions of Rails:

* 1.2.6
* 2.0.2
* 2.1.2
* 2.2.2
* 2.3.2
* 2.3.3
* 2.3.4

Please open up a support ticket on Tender ( http://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

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

17 changes: 8 additions & 9 deletions vendor/plugins/hoptoad_notifier/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ Rake::TestTask.new(:test) do |t|
t.verbose = true
end

desc 'Generate documentation for the hoptoad_notifier plugin.'
Rake::RDocTask.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'HoptoadNotifier'
rdoc.options << '--line-numbers' << '--inline-source'
rdoc.rdoc_files.include('README')
rdoc.rdoc_files.include('lib/**/*.rb')
end

desc 'Run ginger tests'
task :ginger do
$LOAD_PATH << File.join(*%w[vendor ginger lib])
ARGV.clear
ARGV << 'test'
load File.join(*%w[vendor ginger bin ginger])
end

begin
require 'yard'
YARD::Rake::YardocTask.new do |t|
t.files = ['lib/**/*.rb', 'TESTING.rdoc']
end
rescue LoadError
end
8 changes: 0 additions & 8 deletions vendor/plugins/hoptoad_notifier/TESTING

This file was deleted.

8 changes: 8 additions & 0 deletions vendor/plugins/hoptoad_notifier/TESTING.rdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
= For Maintainers:

When developing the Hoptoad Notifier, be sure to use the integration test
against an existing project on staging before pushing to master.

+./script/integration_test.rb <test project's api key> <staging server hostname>+

+./script/integration_test.rb <test project's api key> <staging server hostname> secure+
3 changes: 3 additions & 0 deletions vendor/plugins/hoptoad_notifier/ginger_scenarios.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ def create_scenario(version)
config.scenarios << create_scenario("2.1.2")
config.scenarios << create_scenario("2.2.2")
config.scenarios << create_scenario("2.3.2")
# Rails 2.3.3 has broken params filtering
# config.scenarios << create_scenario("2.3.3")
config.scenarios << create_scenario("2.3.4")
end
Loading

0 comments on commit 7522f9f

Please sign in to comment.