Permalink
Browse files

adding hoptoad to notify me of errors

  • Loading branch information...
1 parent 68050b4 commit dec30340ee78ce47cd20caa16f19e259a5d3035f @ryanb committed Sep 9, 2009
Showing with 2,447 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +1 −0 config/app_config.example.yml
  3. +1 −0 config/deploy.rb
  4. +5 −0 config/initializers/hoptoad.rb
  5. +3 −0 config/preinitializer.rb
  6. +55 −0 vendor/plugins/hoptoad_notifier/INSTALL
  7. +22 −0 vendor/plugins/hoptoad_notifier/MIT-LICENSE
  8. +232 −0 vendor/plugins/hoptoad_notifier/README
  9. +30 −0 vendor/plugins/hoptoad_notifier/Rakefile
  10. +8 −0 vendor/plugins/hoptoad_notifier/TESTING
  11. +28 −0 vendor/plugins/hoptoad_notifier/ginger_scenarios.rb
  12. +1 −0 vendor/plugins/hoptoad_notifier/install.rb
  13. +418 −0 vendor/plugins/hoptoad_notifier/lib/hoptoad_notifier.rb
  14. +26 −0 vendor/plugins/hoptoad_notifier/lib/hoptoad_tasks.rb
  15. +22 −0 vendor/plugins/hoptoad_notifier/recipes/hoptoad.rb
  16. +28 −0 vendor/plugins/hoptoad_notifier/script/integration_test.rb
  17. +66 −0 vendor/plugins/hoptoad_notifier/tasks/hoptoad_notifier_tasks.rake
  18. +148 −0 vendor/plugins/hoptoad_notifier/test/configuration_test.rb
  19. +393 −0 vendor/plugins/hoptoad_notifier/test/controller_test.rb
  20. +113 −0 vendor/plugins/hoptoad_notifier/test/helper.rb
  21. +131 −0 vendor/plugins/hoptoad_notifier/test/hoptoad_tasks_test.rb
  22. +114 −0 vendor/plugins/hoptoad_notifier/test/logger_test.rb
  23. +191 −0 vendor/plugins/hoptoad_notifier/test/notifier_test.rb
  24. +1 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/.gitignore
  25. +20 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/LICENCE
  26. +50 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/README.textile
  27. +57 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/Rakefile
  28. +42 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/bin/ginger
  29. +33 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/ginger.gemspec
  30. +21 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/lib/ginger.rb
  31. +20 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/lib/ginger/configuration.rb
  32. +56 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/lib/ginger/kernel.rb
  33. +24 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/lib/ginger/scenario.rb
  34. +7 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/spec/ginger/configuration_spec.rb
  35. +7 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/spec/ginger/kernel_spec.rb
  36. +50 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/spec/ginger/scenario_spec.rb
  37. +14 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/spec/ginger_spec.rb
  38. +7 −0 vendor/plugins/hoptoad_notifier/vendor/ginger/spec/spec_helper.rb
View
@@ -2,4 +2,5 @@ log/*.log
tmp/**/*
*.sqlite3
database.yml
-public/assets
+app_config.yml
+public/assets
@@ -0,0 +1 @@
+hoptoad_key: 123456789 # replace with real key
View
@@ -39,6 +39,7 @@
run "mkdir #{shared_path}/db"
run "mkdir #{shared_path}/db/sphinx"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
+ put File.read("config/app_config.example.yml"), "#{shared_path}/config/app_config.yml"
puts "Now edit the config files and fill assets folder in #{shared_path}."
end
@@ -0,0 +1,5 @@
+if APP_CONFIG['hoptoad_key']
+ HoptoadNotifier.configure do |config|
+ config.api_key = APP_CONFIG['hoptoad_key']
+ end
+end
View
@@ -0,0 +1,3 @@
+# load app_config.yml
+require 'yaml'
+APP_CONFIG = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
@@ -0,0 +1,55 @@
+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
+------------
+
+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
+
+From your project's RAILS_ROOT, run:
+
+ script/plugin install git://github.com/thoughtbot/hoptoad_notifier.git
+
+CONFIGURATION
+
+You should have something like this in config/initializers/hoptoad.rb.
+
+ HoptoadNotifier.configure do |config|
+ config.api_key = '1234567890abcdef'
+ end
+
+(Please note that this configuration should be in a global configuration, and
+is *not* enrivonment-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 this is in place, all exceptions will be logged to Hoptoad where they can
+be aggregated, filtered, sorted, analyzed, massaged, and searched.
+
+** 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
+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.
@@ -0,0 +1,22 @@
+Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,232 @@
+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
+------------
+
+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
+
+From your project's RAILS_ROOT, run:
+
+ script/plugin install git://github.com/thoughtbot/hoptoad_notifier.git
+
+CONFIGURATION
+
+You should have something like this in config/initializers/hoptoad.rb.
+
+ HoptoadNotifier.configure do |config|
+ config.api_key = '1234567890abcdef'
+ end
+
+(Please note that this configuration should be in a global configuration, and
+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
+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.
+
+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 plugin),
+all errors will be rescued by the #rescue_action_in_public provided by the plugin.
+
+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.
+
+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 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
+ require 'hoptoad_notifier/recipes/hoptoad'
+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}",
+ :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.
+
+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
+ }
+ end
+
+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 #environment_filters or #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
+-------
+
+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::Catcher
+ def notify(thing)
+ # do nothing.
+ end
+ end
+
+SUPPORTED RAILS VERSIONS
+------------------------
+
+The notifier currently supports the following versions of Rails:
+
+* 1.2.6
+* 2.0.2
+* 2.1.2
+* 2.2.2
+* 2.3.2
+
+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 to Eugene Bolshakov for the excellent write-up on GOING BEYOND EXCEPTIONS, which we have included above.
+
@@ -0,0 +1,30 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the hoptoad_notifier plugin.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ 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
@@ -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
+
Oops, something went wrong.

0 comments on commit dec3034

Please sign in to comment.