square-hoptoad_notifier 2.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. data/CHANGELOG +427 -0
  2. data/INSTALL +25 -0
  3. data/MIT-LICENSE +22 -0
  4. data/README.md +435 -0
  5. data/README_FOR_HEROKU_ADDON.md +93 -0
  6. data/Rakefile +227 -0
  7. data/SUPPORTED_RAILS_VERSIONS +10 -0
  8. data/TESTING.rdoc +8 -0
  9. data/generators/hoptoad/hoptoad_generator.rb +88 -0
  10. data/generators/hoptoad/lib/insert_commands.rb +34 -0
  11. data/generators/hoptoad/lib/rake_commands.rb +24 -0
  12. data/generators/hoptoad/templates/capistrano_hook.rb +6 -0
  13. data/generators/hoptoad/templates/hoptoad_notifier_tasks.rake +25 -0
  14. data/generators/hoptoad/templates/initializer.rb +6 -0
  15. data/lib/hoptoad_notifier.rb +153 -0
  16. data/lib/hoptoad_notifier/backtrace.rb +99 -0
  17. data/lib/hoptoad_notifier/capistrano.rb +20 -0
  18. data/lib/hoptoad_notifier/configuration.rb +242 -0
  19. data/lib/hoptoad_notifier/notice.rb +337 -0
  20. data/lib/hoptoad_notifier/rack.rb +42 -0
  21. data/lib/hoptoad_notifier/rails.rb +41 -0
  22. data/lib/hoptoad_notifier/rails/action_controller_catcher.rb +30 -0
  23. data/lib/hoptoad_notifier/rails/controller_methods.rb +68 -0
  24. data/lib/hoptoad_notifier/rails/error_lookup.rb +33 -0
  25. data/lib/hoptoad_notifier/rails/javascript_notifier.rb +42 -0
  26. data/lib/hoptoad_notifier/rails3_tasks.rb +82 -0
  27. data/lib/hoptoad_notifier/railtie.rb +32 -0
  28. data/lib/hoptoad_notifier/sender.rb +83 -0
  29. data/lib/hoptoad_notifier/shared_tasks.rb +29 -0
  30. data/lib/hoptoad_notifier/tasks.rb +83 -0
  31. data/lib/hoptoad_notifier/user_informer.rb +23 -0
  32. data/lib/hoptoad_notifier/version.rb +3 -0
  33. data/lib/hoptoad_tasks.rb +44 -0
  34. data/lib/rails/generators/hoptoad/hoptoad_generator.rb +94 -0
  35. data/lib/templates/javascript_notifier.erb +13 -0
  36. data/lib/templates/rescue.erb +91 -0
  37. data/rails/init.rb +1 -0
  38. data/script/integration_test.rb +38 -0
  39. data/test/backtrace_test.rb +118 -0
  40. data/test/catcher_test.rb +331 -0
  41. data/test/configuration_test.rb +216 -0
  42. data/test/helper.rb +248 -0
  43. data/test/hoptoad_tasks_test.rb +152 -0
  44. data/test/javascript_notifier_test.rb +52 -0
  45. data/test/logger_test.rb +85 -0
  46. data/test/notice_test.rb +448 -0
  47. data/test/notifier_test.rb +222 -0
  48. data/test/rack_test.rb +58 -0
  49. data/test/rails_initializer_test.rb +36 -0
  50. data/test/sender_test.rb +161 -0
  51. data/test/user_informer_test.rb +29 -0
  52. metadata +225 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2007, Tammer Saleh, Thoughtbot, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,435 @@
1
+ HoptoadNotifier
2
+ ===============
3
+
4
+ This is the notifier gem for integrating apps with Hoptoad.
5
+
6
+ When an uncaught exception occurs, HoptoadNotifier will POST the relevant data
7
+ to the Hoptoad server specified in your environment.
8
+
9
+ Help
10
+ ----
11
+
12
+ For help with using Hoptoad and the Hoptoad notifier visit [our support site](http://help.hoptoadapp.com)
13
+
14
+ For discussion of Hoptoad notifier development check out the [mailing list](http://groups.google.com/group/hoptoad-notifier-dev)
15
+
16
+ Rails Installation
17
+ ------------------
18
+
19
+ ### Remove exception_notifier
20
+
21
+ in your ApplicationController, REMOVE this line:
22
+
23
+ include ExceptionNotifiable
24
+
25
+ In your config/environment* files, remove all references to ExceptionNotifier
26
+
27
+ Remove the vendor/plugins/exception_notifier directory.
28
+
29
+ ### Remove hoptoad_notifier plugin
30
+
31
+ Remove the vendor/plugins/hoptoad_notifier directory before installing the gem, or run:
32
+
33
+ script/plugin remove hoptoad_notifier
34
+
35
+ ### Rails 3.x
36
+
37
+ Add the hoptoad_notifier gem to your Gemfile. In Gemfile:
38
+
39
+ gem "hoptoad_notifier", "~> 2.3"
40
+
41
+ Then from your project's RAILS_ROOT, run:
42
+
43
+ bundle install
44
+ script/rails generate hoptoad --api-key your_key_here
45
+
46
+ That's it!
47
+
48
+ ### Rails 2.x
49
+
50
+ Add the hoptoad_notifier gem to your app. In config/environment.rb:
51
+
52
+ config.gem 'hoptoad_notifier'
53
+
54
+ Then from your project's RAILS_ROOT, run:
55
+
56
+ rake gems:install
57
+ rake gems:unpack GEM=hoptoad_notifier
58
+ script/generate hoptoad --api-key your_key_here
59
+
60
+ As always, if you choose not to vendor the hoptoad_notifier gem, make sure
61
+ every server you deploy to has the gem installed or your application won't start.
62
+
63
+ ### Rails 1.2.6
64
+
65
+ Install the hoptoad_notifier gem:
66
+
67
+ gem install hoptoad_notifier
68
+
69
+ Once installed, you should vendor the hoptoad_notifier gem:
70
+
71
+ mkdir vendor/gems
72
+ cd vendor/gems
73
+ gem unpack hoptoad_notifier
74
+
75
+ And then add the following to the Rails::Initializer.run do |config|
76
+ block in environment.rb so that the vendored gem is loaded.
77
+
78
+ # Add the vendor/gems/*/lib directories to the LOAD_PATH
79
+ config.load_paths += Dir.glob(File.join(RAILS_ROOT, 'vendor', 'gems', '*', 'lib'))
80
+
81
+ Next add something like this at the bottom of your config/environment.rb:
82
+
83
+ require 'hoptoad_notifier'
84
+ require 'hoptoad_notifier/rails'
85
+ HoptoadNotifier.configure do |config|
86
+ config.api_key = 'your_key_here'
87
+ end
88
+
89
+ You will also need to copy the hoptoad_notifier_tasks.rake file into your
90
+ RAILS_ROOT/lib/tasks directory in order for the rake hoptoad:test task to work:
91
+
92
+ cp vendor/gems/hoptoad_notifier-*/generators/hoptoad/templates/hoptoad_notifier_tasks.rake lib/tasks
93
+
94
+ As always, if you choose not to vendor the hoptoad_notifier gem, make sure
95
+ every server you deploy to has the gem installed or your application won't start.
96
+
97
+ ### Upgrading From Earlier Versions of Hoptoad
98
+
99
+ If you're currently using the plugin version (if you have a
100
+ vendor/plugins/hoptoad_notifier directory, you are), you'll need to perform a
101
+ few extra steps when upgrading to the gem version.
102
+
103
+ Add the hoptoad_notifier gem to your app. In config/environment.rb:
104
+
105
+ config.gem 'hoptoad_notifier'
106
+
107
+ Remove the plugin:
108
+
109
+ rm -rf vendor/plugins/hoptoad_notifier
110
+
111
+ Make sure the following line DOES NOT appear in your ApplicationController file:
112
+
113
+ include HoptoadNotifier::Catcher
114
+
115
+ If it does, remove it. The new catcher is automatically included by the gem
116
+ version of Hoptoad.
117
+
118
+ Before running the hoptoad generator, you need to find your project's API key.
119
+ Log in to your account at hoptoadapp.com, and click on the "Projects" button.
120
+ Then, find your project in the list, and click on its name. In the left-hand
121
+ column, you'll see an "Edit this project" button. Click on that to get your
122
+ project's API. (If you accidentally use your personal API auth_token, you won't
123
+ be able to install the gem.)
124
+
125
+ Then from your project's RAILS_ROOT, run:
126
+
127
+ rake gems:install
128
+ script/generate hoptoad --api-key your_key_here
129
+
130
+ Once installed, you should vendor the hoptoad_notifier gem.
131
+
132
+ rake gems:unpack GEM=hoptoad_notifier
133
+
134
+ As always, if you choose not to vendor the hoptoad_notifier gem, make sure
135
+ every server you deploy to has the gem installed or your application won't
136
+ start.
137
+
138
+ ### Upgrading from Earlier Versions of the Hoptoad Gem (with config.gem)
139
+
140
+ If you're currently using the gem version of the hoptoad_notifier and have
141
+ a version of Rails that uses config.gem (in the 2.x series), there is
142
+ a step or two that you need to do to upgrade. First, you need to remove
143
+ the old version of the gem from vendor/gems:
144
+
145
+ rm -rf vendor/gems/hoptoad_notifier-X.X.X
146
+
147
+ Then you must remove the hoptoad_notifier_tasks.rake file from lib:
148
+
149
+ rm lib/tasks/hoptoad_notifier_tasks.rake
150
+
151
+ You can them continue to install normally. If you don't remove the rake file,
152
+ you will be unable to unpack this gem (Rails will think it's part of the
153
+ framework).
154
+
155
+ ### Testing it out
156
+
157
+ You can test that Hoptoad is working in your production environment by using
158
+ this rake task (from RAILS_ROOT):
159
+
160
+ rake hoptoad:test
161
+
162
+ If everything is configured properly, that task will send a notice to Hoptoad
163
+ which will be visible immediately.
164
+
165
+ Rack
166
+ ----
167
+
168
+ In order to use hoptoad_notifier in a non-Rails rack app, just load the
169
+ hoptoad_notifier, configure your API key, and use the HoptoadNotifier::Rack
170
+ middleware:
171
+
172
+ require 'rack'
173
+ require 'hoptoad_notifier'
174
+
175
+ HoptoadNotifier.configure do |config|
176
+ config.api_key = 'my_api_key'
177
+ end
178
+
179
+ app = Rack::Builder.app do
180
+ use HoptoadNotifier::Rack
181
+ run lambda { |env| raise "Rack down" }
182
+ end
183
+
184
+ Sinatra
185
+ -------
186
+
187
+ Using hoptoad_notifier in a Sinatra app is just like a Rack app, but you have
188
+ to disable Sinatra's error rescuing functionality:
189
+
190
+ require 'sinatra/base'
191
+ require 'hoptoad_notifier'
192
+
193
+ HoptoadNotifier.configure do |config|
194
+ config.api_key = 'my_api_key'
195
+ end
196
+
197
+ class MyApp < Sinatra::Default
198
+ use HoptoadNotifier::Rack
199
+ enable :raise_errors
200
+
201
+ get "/" do
202
+ raise "Sinatra has left the building"
203
+ end
204
+ end
205
+
206
+ Usage
207
+ -----
208
+
209
+ For the most part, Hoptoad works for itself. Once you've included the notifier
210
+ in your ApplicationController (which is now done automatically by the gem),
211
+ all errors will be rescued by the #rescue_action_in_public provided by the gem.
212
+
213
+ If you want to log arbitrary things which you've rescued yourself from a
214
+ controller, you can do something like this:
215
+
216
+ ...
217
+ rescue => ex
218
+ notify_hoptoad(ex)
219
+ flash[:failure] = 'Encryptions could not be rerouted, try again.'
220
+ end
221
+ ...
222
+
223
+ The #notify_hoptoad call will send the notice over to Hoptoad for later
224
+ analysis. While in your controllers you use the notify_hoptoad method, anywhere
225
+ else in your code, use HoptoadNotifier.notify.
226
+
227
+ To perform custom error processing after Hoptoad has been notified, define the
228
+ instance method #rescue_action_in_public_without_hoptoad(exception) in your
229
+ controller.
230
+
231
+ Tracking deployments in Hoptoad
232
+ -------------------------------
233
+
234
+ Paying Hoptoad plans support the ability to track deployments of your application in Hoptoad.
235
+ By notifying Hoptoad of your application deployments, all errors are resolved when a deploy occurs,
236
+ so that you'll be notified again about any errors that reoccur after a deployment.
237
+
238
+ Additionally, it's possible to review the errors in Hoptoad that occurred before and after a deploy.
239
+
240
+ When Hoptoad is installed as a gem, you need to add
241
+
242
+ require 'hoptoad_notifier/capistrano'
243
+
244
+ to your deploy.rb
245
+
246
+ If you don't use Capistrano, then you can use the following rake task from your
247
+ deployment process to notify Hoptoad:
248
+
249
+ rake hoptoad:deploy TO=#{rails_env} REVISION=#{current_revision} REPO=#{repository} USER=#{local_user}
250
+
251
+ Going beyond exceptions
252
+ -----------------------
253
+
254
+ You can also pass a hash to notify_hoptoad method and store whatever you want,
255
+ not just an exception. And you can also use it anywhere, not just in
256
+ controllers:
257
+
258
+ begin
259
+ params = {
260
+ # params that you pass to a method that can throw an exception
261
+ }
262
+ my_unpredicable_method(params)
263
+ rescue => e
264
+ HoptoadNotifier.notify(
265
+ :error_class => "Special Error",
266
+ :error_message => "Special Error: #{e.message}",
267
+ :parameters => params
268
+ )
269
+ end
270
+
271
+ While in your controllers you use the notify_hoptoad method, anywhere else in
272
+ your code, use HoptoadNotifier.notify. Hoptoad will get all the information
273
+ about the error itself. As for a hash, these are the keys you should pass:
274
+
275
+ * :error_class - Use this to group similar errors together. When Hoptoad catches an exception it sends the class name of that exception object.
276
+ * :error_message - This is the title of the error you see in the errors list. For exceptions it is "#{exception.class.name}: #{exception.message}"
277
+ * :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.
278
+
279
+ Hoptoad merges the hash you pass with these default options:
280
+
281
+ {
282
+ :api_key => HoptoadNotifier.api_key,
283
+ :error_message => 'Notification',
284
+ :backtrace => caller,
285
+ :parameters => {},
286
+ :session => {}
287
+ }
288
+
289
+ You can override any of those parameters.
290
+
291
+ ### Sending shell environment variables when "Going beyond exceptions"
292
+
293
+ One common request we see is to send shell environment variables along with
294
+ manual exception notification. We recommend sending them along with CGI data
295
+ or Rack environment (:cgi_data or :rack_env keys, respectively.)
296
+
297
+ See HoptoadNotifier::Notice#initialize in lib/hoptoad_notifier/notice.rb for
298
+ more details.
299
+
300
+ Filtering
301
+ ---------
302
+
303
+ You can specify a whitelist of errors, that Hoptoad will not report on. Use
304
+ this feature when you are so apathetic to certain errors that you don't want
305
+ them even logged.
306
+
307
+ This filter will only be applied to automatic notifications, not manual
308
+ notifications (when #notify is called directly).
309
+
310
+ Hoptoad ignores the following exceptions by default:
311
+
312
+ AbstractController::ActionNotFound
313
+ ActiveRecord::RecordNotFound
314
+ ActionController::RoutingError
315
+ ActionController::InvalidAuthenticityToken
316
+ ActionController::UnknownAction
317
+ CGI::Session::CookieStore::TamperedWithCookie
318
+
319
+ To ignore errors in addition to those, specify their names in your Hoptoad
320
+ configuration block.
321
+
322
+ HoptoadNotifier.configure do |config|
323
+ config.api_key = '1234567890abcdef'
324
+ config.ignore << "ActiveRecord::IgnoreThisError"
325
+ end
326
+
327
+ To ignore *only* certain errors (and override the defaults), use the
328
+ #ignore_only attribute.
329
+
330
+ HoptoadNotifier.configure do |config|
331
+ config.api_key = '1234567890abcdef'
332
+ config.ignore_only = ["ActiveRecord::IgnoreThisError"]
333
+ end
334
+
335
+ To ignore certain user agents, add in the #ignore_user_agent attribute as a
336
+ string or regexp:
337
+
338
+ HoptoadNotifier.configure do |config|
339
+ config.api_key = '1234567890abcdef'
340
+ config.ignore_user_agent << /Ignored/
341
+ config.ignore_user_agent << 'IgnoredUserAgent'
342
+ end
343
+
344
+ To ignore exceptions based on other conditions, use #ignore_by_filter:
345
+
346
+ HoptoadNotifier.configure do |config|
347
+ config.api_key = '1234567890abcdef'
348
+ config.ignore_by_filter do |exception_data|
349
+ true if exception_data[:error_class] == "RuntimeError"
350
+ end
351
+ end
352
+
353
+ To replace sensitive information sent to the Hoptoad service with [FILTERED] use #params_filters:
354
+
355
+ HoptoadNotifier.configure do |config|
356
+ config.api_key = '1234567890abcdef'
357
+ config.params_filters << "credit_card_number"
358
+ end
359
+
360
+ Note that, when rescuing exceptions within an ActionController method,
361
+ hoptoad_notifier will reuse filters specified by #filter_parameter_logging.
362
+
363
+ Testing
364
+ -------
365
+
366
+ When you run your tests, you might notice that the Hoptoad service is recording
367
+ notices generated using #notify when you don't expect it to. You can
368
+ use code like this in your test_helper.rb to redefine that method so those
369
+ errors are not reported while running tests.
370
+
371
+ module HoptoadNotifier
372
+ def self.notify(thing)
373
+ # do nothing.
374
+ end
375
+ end
376
+
377
+ Proxy Support
378
+ -------------
379
+
380
+ The notifier supports using a proxy, if your server is not able to directly reach the Hoptoad servers. To configure the proxy settings, added the following information to your Hoptoad configuration block.
381
+
382
+ HoptoadNotifier.configure do |config|
383
+ config.proxy_host = ...
384
+ config.proxy_port = ...
385
+ config.proxy_user = ...
386
+ config.proxy_pass = ...
387
+
388
+ Supported Rails versions
389
+ ------------------------
390
+
391
+ See SUPPORTED_RAILS_VERSIONS for a list of official supported versions of
392
+ Rails.
393
+
394
+ Please open up a support ticket on Tender ( http://help.hoptoadapp.com ) if
395
+ you're using a version of Rails that is not listed above and the notifier is
396
+ not working properly.
397
+
398
+ Javascript Notifer
399
+ ------------------
400
+
401
+ To automatically include the Javascript node on every page, use this helper method from your layouts:
402
+
403
+ <%= hoptoad_javascript_notifier %>
404
+
405
+ It's important to insert this very high in the markup, above all other javascript. Example:
406
+
407
+ <!DOCTYPE html>
408
+ <html>
409
+ <head>
410
+ <meta charset="utf8">
411
+ <%= hoptoad_javascript_notifier %>
412
+ <!-- more javascript -->
413
+ </head>
414
+ <body>
415
+ ...
416
+ </body>
417
+ </html>
418
+
419
+ This helper will automatically use the API key, host, and port specified in the configuration.
420
+
421
+ Credits
422
+ -------
423
+
424
+ ![thoughtbot](http://thoughtbot.com/images/tm/logo.png)
425
+
426
+ HoptoadNotifier is maintained and funded by [thoughtbot, inc](http://thoughtbot.com/community)
427
+
428
+ Thank you to all [the contributors](https://github.com/thoughtbot/hoptoad_notifier/contributors)!
429
+
430
+ The names and logos for thoughtbot are trademarks of thoughtbot, inc.
431
+
432
+ License
433
+ -------
434
+
435
+ HoptoadNotifier is Copyright © 2008-2011 thoughtbot. It is free software, and may be redistributed under the terms specified in the MIT-LICENSE file.