rollbar 0.10.4 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change Log
2
2
 
3
+ **0.10.5**
4
+ - Add built-in support for Sidekiq as async handler
5
+
3
6
  **0.10.4**
4
7
  - Fix exception in the exception catcher when Rollbar is disabled
5
8
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
- # Rollbar [![Build Status](https://secure.travis-ci.org/rollbar/rollbar-gem.png?branch=master)](https://travis-ci.org/rollbar/rollbar-gem)
1
+ # Rollbar notifier for Ruby [![Build Status](https://secure.travis-ci.org/rollbar/rollbar-gem.png?branch=master)](https://travis-ci.org/rollbar/rollbar-gem)
2
2
 
3
- Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https://rollbar.com). Requires a Rollbar account (you can [sign up for free](https://rollbar.com/signup)). Basic integration in a Rails 3 app should only take a few minutes.
3
+ Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https://rollbar.com).
4
+
5
+ <!-- Sub:[TOC] -->
4
6
 
5
7
  ## Installation
6
8
 
@@ -10,43 +12,57 @@ Add this line to your application's Gemfile:
10
12
 
11
13
  And then execute:
12
14
 
13
- $ bundle install
15
+ ```bash
16
+ $ bundle install
17
+ ```
14
18
 
15
19
  Or install it yourself as:
16
20
 
17
- $ gem install rollbar
21
+ ```bash
22
+ $ gem install rollbar
23
+ ```
18
24
 
19
25
  Then, run the following command from your rails root:
20
26
 
21
- $ rails generate rollbar your-rollbar-post_server_item-token
27
+ ```bash
28
+ $ rails generate rollbar POST_SERVER_ITEM_ACCESS_TOKEN
29
+ ```
22
30
 
23
- That will create the file `config/initializers/rollbar.rb`, which holds the configuration values (currently just your access token). Make sure you're using the `post_server_item` access token.
31
+ That will create the file ```config/initializers/rollbar.rb```, which holds the configuration values (currently just your access token). Make sure you're using the ```post_server_item``` access token.
24
32
 
25
33
  If you want to store your access token outside of your repo, run the same command without arguments:
26
34
 
27
- $ rails generate rollbar
35
+ ```bash
36
+ $ rails generate rollbar
37
+ ```
28
38
 
29
- Then, create an environment variable `ROLLBAR_ACCESS_TOKEN` and set it to your server-side access token.
39
+ Then, create an environment variable ```ROLLBAR_ACCESS_TOKEN``` and set it to your server-side access token.
30
40
 
31
- $ export ROLLBAR_ACCESS_TOKEN=your-rollbar-post_server_item-token
41
+ ```bash
42
+ $ export ROLLBAR_ACCESS_TOKEN=POST_SERVER_ITEM_ACCESS_TOKEN
43
+ ```
32
44
 
33
- or
34
-
35
- $ heroku config:add ROLLBAR_ACCESS_TOKEN=your-rollbar-post_server_item-token
45
+ ### For Heroku users
36
46
 
37
- if you are using Heroku.
47
+ ```bash
48
+ $ heroku config:add ROLLBAR_ACCESS_TOKEN=POST_SERVER_ITEM_ACCESS_TOKEN
49
+ ```
38
50
 
39
51
  That's all you need to use Rollbar with Rails.
40
52
 
53
+ ## Test your installation
54
+
41
55
  To confirm that it worked, run:
42
56
 
43
- $ rake rollbar:test
57
+ ```bash
58
+ $ rake rollbar:test
59
+ ```
44
60
 
45
61
  This will raise an exception within a test request; if it works, you'll see a stacktrace in the console, and the exception will appear in the Rollbar dashboard.
46
62
 
47
63
  ## Manually reporting exceptions and messages
48
64
 
49
- To report a caught exception to Rollbar, simply call `Rollbar.report_exception`:
65
+ To report a caught exception to Rollbar, simply call ```Rollbar.report_exception```:
50
66
 
51
67
  ```ruby
52
68
  begin
@@ -79,55 +95,72 @@ Rollbar.report_message("Login successful")
79
95
  Rollbar.report_message("Login successful", "info", :user => @user)
80
96
  ```
81
97
 
98
+ ## Data sanitization (scrubbing)
82
99
 
83
- ## Person tracking
100
+ By default, the notifier will "scrub" the following fields from requests before sending to Rollbar
101
+
102
+ - ```:passwd```
103
+ - ```:password```
104
+ - ```:password_confirmation```
105
+ - ```:secret```
106
+ - ```:confirm_password```
107
+ - ```:password_confirmation```
108
+ - ```:secret_token```
84
109
 
85
- Rollbar will send information about the current user (called a "person" in Rollbar parlance) along with each error report, when available. This works by calling the `current_user` controller method. The return value should be an object with an `id` method and, optionally, `username` and `email` methods.
110
+ If a request contains one of these fields, the value will be replaced with a ```"*"``` before being sent.
86
111
 
87
- If the gem should call a controller method besides `current_user`, add the following in `config/initializers/rollbar.rb`:
112
+ Additional fields can be scrubbed by updating ```Rollbar.configuration.scrub_fields```:
88
113
 
89
114
  ```ruby
90
- config.person_method = "my_current_user"
115
+ # scrub out the "user_password" field
116
+ Rollbar.configuration.scrub_fields |= [:user_password]
91
117
  ```
92
118
 
93
- If the methods to extract the `id`, `username`, and `email` from the object returned by the `person_method` have other names, configure like so in `config/initializers/rollbar.rb`:
119
+ ## Person tracking
120
+
121
+ Rollbar will send information about the current user (called a "person" in Rollbar parlance) along with each error report, when available. This works by calling the ```current_user``` controller method. The return value should be an object with an ```id``` method and, optionally, ```username``` and ```email``` methods.
122
+
123
+ If the gem should call a controller method besides ```current_user```, add the following in ```config/initializers/rollbar.rb```:
94
124
 
95
125
  ```ruby
96
- config.person_id_method = "user_id" # default is "id"
97
- config.person_username_method = "user_name" # default is "username"
98
- config.person_email_method = "email_address" # default is "email"
126
+ config.person_method = "my_current_user"
99
127
  ```
100
128
 
129
+ If the methods to extract the ```id```, ```username```, and ```email``` from the object returned by the ```person_method``` have other names, configure like so in ```config/initializers/rollbar.rb```:
130
+
131
+ ```ruby
132
+ config.person_id_method = "user_id" # default is "id"
133
+ config.person_username_method = "user_name" # default is "username"
134
+ config.person_email_method = "email_address" # default is "email"
135
+ ```
101
136
 
102
137
  ## Including additional runtime data
103
138
 
104
- You can provide a lambda that will be called for each exception or message report. `custom_data_method` should be a lambda that takes no arguments and returns a hash.
139
+ You can provide a lambda that will be called for each exception or message report. ```custom_data_method``` should be a lambda that takes no arguments and returns a hash.
105
140
 
106
- Add the following in `config/initializers/rollbar.rb`:
141
+ Add the following in ```config/initializers/rollbar.rb```:
107
142
 
108
143
  ```ruby
109
- config.custom_data_method = lambda {
110
- { :some_key => :some_value, :complex_key => {:a => 1, :b => [2, 3, 4]} }
111
- }
144
+ config.custom_data_method = lambda {
145
+ { :some_key => :some_value, :complex_key => {:a => 1, :b => [2, 3, 4]} }
146
+ }
112
147
  ```
113
148
 
114
149
  This data will appear in the Occurrences tab and on the Occurrence Detail pages in the Rollbar interface.
115
150
 
116
-
117
151
  ## Exception level filters
118
152
 
119
- By default, all exceptions reported through `Rollbar.report_exception()` are reported at the "error" level, except for the following, which are reported at "warning" level:
120
-
121
- - ActiveRecord::RecordNotFound
122
- - AbstractController::ActionNotFound
123
- - ActionController::RoutingError
153
+ By default, all exceptions reported through ```Rollbar.report_exception()``` are reported at the "error" level, except for the following, which are reported at "warning" level:
124
154
 
125
- If you'd like to customize this list, see the example code in `config/initializers/rollbar.rb`. Supported levels: "critical", "error", "warning", "info", "debug", "ignore". Set to "ignore" to cause the exception not to be reported at all.
155
+ - ```ActiveRecord::RecordNotFound```
156
+ - ```AbstractController::ActionNotFound```
157
+ - ```ActionController::RoutingError```
126
158
 
159
+ If you'd like to customize this list, see the example code in ```config/initializers/rollbar.rb```. Supported levels: "critical", "error", "warning", "info", "debug", "ignore". Set to "ignore" to cause the exception not to be reported at all.
127
160
 
128
161
  ## Silencing exceptions at runtime
129
162
 
130
- If you just want to disable exception reporting for a single block, use `Rollbar.silenced`:
163
+ If you just want to disable exception reporting for a single block, use ```Rollbar.silenced```:
131
164
 
132
165
  ```ruby
133
166
  Rollbar.silenced {
@@ -135,67 +168,104 @@ Rollbar.silenced {
135
168
  }
136
169
  ```
137
170
 
138
-
139
171
  ## Asynchronous reporting
140
172
 
141
- By default, all messages are reported synchronously. You can enable asynchronous reporting by adding the following in `config/initializers/rollbar.rb`:
173
+ By default, all messages are reported synchronously. You can enable asynchronous reporting with [girl_friday](https://github.com/mperham/girl_friday) or [Sidekiq](https://github.com/mperham/sidekiq).
174
+
175
+ ### Using girl_friday
176
+
177
+ Add the following in ```config/initializers/rollbar.rb```:
142
178
 
143
179
  ```ruby
144
- config.use_async = true
180
+ config.use_async = true
145
181
  ```
146
182
 
147
- Rollbar uses [girl_friday](https://github.com/mperham/girl_friday) to handle asynchronous reporting when installed, and falls back to Threading if girl_friday is not installed.
183
+ Asynchronous reporting falls back to Threading if girl_friday is not installed.
184
+
185
+ ### Using Sidekiq
186
+
187
+ Add the following in ```config/initializers/rollbar.rb```:
188
+
189
+ ```ruby
190
+ config.use_sidekiq = true
191
+ ```
148
192
 
149
- You can supply your own handler using `config.async_handler`. The handler should schedule the payload for later processing (i.e. with a delayed_job, in a resque queue, etc.) and should itself return immediately. For example:
193
+ You can also supply custom Sidekiq options:
150
194
 
151
195
  ```ruby
152
- config.async_handler = Proc.new { |payload|
153
- Thread.new { Rollbar.process_payload(payload) }
154
- }
196
+ config.use_sidekiq = { 'queue' => 'my_queue' }
155
197
  ```
156
198
 
157
- Make sure you pass `payload` to `Rollbar.process_payload` in your own implementation.
199
+ Start the redis server:
200
+
201
+ ```bash
202
+ $ redis-server
203
+ ```
204
+
205
+ Start Sidekiq from the root directory of your Rails app and declare the name of your queue. Unless you've configured otherwise, the queue name is "rollbar":
206
+
207
+ ```bash
208
+ $ bundle exec sidekiq -q rollbar
209
+ ```
158
210
 
211
+ ### Using another handler
212
+
213
+ You can supply your own handler using ```config.async_handler```. The handler should schedule the payload for later processing (i.e. with a delayed_job, in a resque queue, etc.) and should itself return immediately. For example:
214
+
215
+ ```ruby
216
+ config.async_handler = Proc.new { |payload|
217
+ Thread.new { Rollbar.process_payload(payload) }
218
+ }
219
+ ```
220
+
221
+ Make sure you pass ```payload``` to ```Rollbar.process_payload``` in your own implementation.
159
222
 
160
223
  ## Using with rollbar-agent
161
224
 
162
- For even more asynchrony, you can configure the gem to write to a file instead of sending the payload to Rollbar servers directly. [rollbar-agent](https://github.com/rollbar/rollbar-agent) can then be hooked up to this file to actually send the payload across. To enable, add the following in `config/initializers/rollbar.rb`:
225
+ For even more asynchrony, you can configure the gem to write to a file instead of sending the payload to Rollbar servers directly. [rollbar-agent](https://github.com/rollbar/rollbar-agent) can then be hooked up to this file to actually send the payload across. To enable, add the following in ```config/initializers/rollbar.rb```:
163
226
 
164
227
  ```ruby
165
- config.write_to_file = true
166
- # optional, defaults to "#{AppName}.rollbar"
167
- config.filepath = '/path/to/file.rollbar' #should end in '.rollbar' for use with rollbar-agent
228
+ config.write_to_file = true
229
+ # optional, defaults to "#{AppName}.rollbar"
230
+ config.filepath = '/path/to/file.rollbar' #should end in '.rollbar' for use with rollbar-agent
168
231
  ```
169
232
 
170
233
  For this to work, you'll also need to set up rollbar-agent--see its docs for details.
171
234
 
172
-
173
235
  ## Deploy Tracking with Capistrano
174
236
 
175
- Add the following to `deploy.rb`:
237
+ Add the following to ```deploy.rb```:
176
238
 
177
239
  ```ruby
178
240
  require 'rollbar/capistrano'
179
- set :rollbar_token, 'your-rollbar-project-access-token'
241
+ set :rollbar_token, 'POST_SERVER_ITEM_ACCESS_TOKEN'
180
242
  ```
181
243
 
182
244
  Available options:
183
245
 
184
- - `rollbar_token` - the same project access token as you used for the `rails generate rollbar` command; find it in `config/initializers/rollbar.rb`. (It's repeated here for performance reasons, so the rails environment doesn't have to be initialized.)
185
- - `rollbar_env` - deploy environment name, `rails_env` by default
246
+ <dl>
247
+ <dt>rollbar_token</dt>
248
+ <dd>The same project access token as you used for the ```rails generate rollbar``` command; find it in ```config/initializers/rollbar.rb```. (It's repeated here for performance reasons, so the rails environment doesn't have to be initialized.)
249
+ </dd>
250
+ <dt>rollbar_env</dt>
251
+ <dd>Deploy environment name
252
+
253
+ Default: ```rails_env```
254
+
255
+ </dd>
256
+ </dl>
186
257
 
187
- For `capistrano/multistage`, try:
258
+ For ```capistrano/multistage```, try:
188
259
 
189
260
  ```ruby
190
261
  set(:rollbar_env) { stage }
191
262
  ```
192
263
 
193
-
194
264
  ## Counting specific gems as in-project code
195
265
 
196
- In the Rollbar interface, stacktraces are shown with in-project code expanded and other code collapsed. Stack frames are counted as in-project if they occur in a file that is inside of the `configuration.root` (automatically set to `Rails.root` if you're using Rails). The collapsed sections can be expanded by clicking on them.
266
+ In the Rollbar interface, stacktraces are shown with in-project code expanded and other code collapsed. Stack frames are counted as in-project if they occur in a file that is inside of the `configuration.root` (automatically set to ```Rails.root``` if you're using Rails). The collapsed sections can be expanded by clicking on them.
197
267
 
198
- If you want code from some specific gems to start expanded as well, you can configure this in `config/initializers/rollbar.rb`:
268
+ If you want code from some specific gems to start expanded as well, you can configure this in ```config/initializers/rollbar.rb```:
199
269
 
200
270
  ```ruby
201
271
  Rollbar.configure do |config |
@@ -204,10 +274,9 @@ Rollbar.configure do |config |
204
274
  end
205
275
  ```
206
276
 
207
-
208
277
  ## Using with Goalie
209
278
 
210
- If you're using [Goalie](https://github.com/obvio171/goalie) for custom error pages, you may need to explicitly add `require 'goalie'` to `config/application.rb` (in addition to `require 'goalie/rails'`) so that the monkeypatch will work. (This will be obvious if it is needed because your app won't start up: you'll see a cryptic error message about `Goalie::CustomErrorPages.render_exception` not being defined.)
279
+ If you're using [Goalie](https://github.com/obvio171/goalie) for custom error pages, you may need to explicitly add ```require 'goalie'``` to ```config/application.rb``` (in addition to ```require 'goalie/rails'```) so that the monkeypatch will work. (This will be obvious if it is needed because your app won't start up: you'll see a cryptic error message about ```Goalie::CustomErrorPages.render_exception``` not being defined.)
211
280
 
212
281
 
213
282
  ## Using with Resque
@@ -217,20 +286,20 @@ Check out [resque-rollbar](https://github.com/CrowdFlower/resque-rollbar) for us
217
286
 
218
287
  ## Using with Zeus
219
288
 
220
- Some users have reported problems with Zeus when `rake` was not explicitly included in their Gemfile. If the zeus server fails to start after installing the rollbar gem, try explicitly adding `gem 'rake'` to your `Gemfile`. See [this thread](https://github.com/rollbar/rollbar-gem/issues/30) for more information.
289
+ Some users have reported problems with Zeus when ```rake``` was not explicitly included in their Gemfile. If the zeus server fails to start after installing the rollbar gem, try explicitly adding ```gem 'rake'``` to your ```Gemfile```. See [this thread](https://github.com/rollbar/rollbar-gem/issues/30) for more information.
221
290
 
222
291
 
223
292
  ## Help / Support
224
293
 
225
- If you run into any issues, please email us at `support@rollbar.com`
294
+ If you run into any issues, please email us at [support@rollbar.com](mailto:support@rollbar.com)
226
295
 
227
296
 
228
297
  ## Contributing
229
298
 
230
299
  1. Fork it
231
- 2. Create your feature branch (`git checkout -b my-new-feature`)
232
- 3. Commit your changes (`git commit -am 'Added some feature'`)
233
- 4. Push to the branch (`git push origin my-new-feature`)
300
+ 2. Create your feature branch (```git checkout -b my-new-feature```)
301
+ 3. Commit your changes (```git commit -am 'Added some feature'```)
302
+ 4. Push to the branch (```git push origin my-new-feature```)
234
303
  5. Create new Pull Request
235
304
 
236
- We're using RSpec for testing. Run the test suite with `rake spec`. Tests for pull requests are appreciated but not required. (If you don't include a test, we'll write one before merging.)
305
+ We're using RSpec for testing. Run the test suite with ```rake spec```. Tests for pull requests are appreciated but not required. (If you don't include a test, we'll write one before merging.)
data/THANKS.md CHANGED
@@ -4,8 +4,10 @@ Huge thanks to the following contributors (by github username). For the most up-
4
4
 
5
5
  - [arr-ee](https://github.com/arr-ee)
6
6
  - [dimko](https://github.com/dimko)
7
+ - [fabsays](https://github.com/fabsays)
7
8
  - [firstbanco](https://github.com/firstbanco)
8
9
  - [ixti](https://github.com/ixti)
10
+ - [jeremyvdw](https://github.com/jeremyvdw)
9
11
  - [johnknott](https://github.com/johnknott)
10
12
  - [JoshuaOSHickman](https://github.com/JoshuaOSHickman)
11
13
  - [juggler](https://github.com/juggler)
@@ -36,4 +36,9 @@ Rollbar.configure do |config|
36
36
  # config.async_handler = Proc.new { |payload|
37
37
  # Thread.new { Rollbar.process_payload(payload) }
38
38
  # }
39
+
40
+ # Enable delayed reporting (using Sidekiq)
41
+ # config.use_sidekiq = true
42
+ # You can supply custom Sidekiq options:
43
+ # config.use_sidekiq = { 'queue' => 'my_queue' }
39
44
  end
@@ -21,6 +21,7 @@ module Rollbar
21
21
  attr_accessor :person_email_method
22
22
  attr_accessor :root
23
23
  attr_accessor :scrub_fields
24
+ attr_accessor :use_sidekiq
24
25
  attr_accessor :use_async
25
26
  attr_accessor :use_eventmachine
26
27
  attr_accessor :web_base
@@ -52,11 +53,20 @@ module Rollbar
52
53
  @scrub_fields = [:passwd, :password, :password_confirmation, :secret,
53
54
  :confirm_password, :password_confirmation, :secret_token]
54
55
  @use_async = false
56
+ @use_sidekiq = false
55
57
  @use_eventmachine = false
56
58
  @web_base = DEFAULT_WEB_BASE
57
59
  @write_to_file = false
58
60
  end
59
61
 
62
+ def use_sidekiq=(value)
63
+ if value
64
+ require 'rollbar/delay/sidekiq' if defined?(Sidekiq)
65
+ @use_async = true
66
+ @async_handler = Rollbar::Delay::Sidekiq.method(:handle)
67
+ end
68
+ end
69
+
60
70
  def use_eventmachine=(value)
61
71
  require 'em-http-request' if value
62
72
  @use_eventmachine = value
@@ -0,0 +1,21 @@
1
+ require 'sidekiq'
2
+
3
+ module Rollbar
4
+ module Delay
5
+ class Sidekiq
6
+ OPTIONS = { 'queue' => 'rollbar', 'class' => self.name }.freeze
7
+
8
+ def self.handle(payload)
9
+ item = @use_sidekiq.is_a?(Hash) ? OPTIONS.merge(@use_sidekiq) : OPTIONS
10
+
11
+ ::Sidekiq::Client.push item.merge('args' => [payload])
12
+ end
13
+
14
+ include ::Sidekiq::Worker
15
+
16
+ def perform(*args)
17
+ Rollbar.process_payload(*args)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "0.10.4"
2
+ VERSION = "0.10.5"
3
3
  end
data/spec/rollbar_spec.rb CHANGED
@@ -290,6 +290,28 @@ describe Rollbar do
290
290
  config.async_handler = Rollbar.method(:default_async_handler)
291
291
  end
292
292
  end
293
+
294
+ it "should send the payload to sidekiq delayer" do
295
+ module Rollbar
296
+ module Delay
297
+ class Sidekiq
298
+ end
299
+ end
300
+ end
301
+
302
+ Rollbar::Delay::Sidekiq.should_receive(:handle).with(anything)
303
+
304
+ Rollbar.configure do |config|
305
+ config.use_sidekiq = { 'queue' => 'test_queue' }
306
+ end
307
+
308
+ Rollbar.report_exception(@exception)
309
+
310
+ Rollbar.configure do |config|
311
+ config.use_async = false
312
+ config.async_handler = Rollbar.method(:default_async_handler)
313
+ end
314
+ end
293
315
  end
294
316
 
295
317
  context 'message_data' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.4
4
+ version: 0.10.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -134,6 +134,7 @@ files:
134
134
  - lib/rollbar/better_errors.rb
135
135
  - lib/rollbar/capistrano.rb
136
136
  - lib/rollbar/configuration.rb
137
+ - lib/rollbar/delay/sidekiq.rb
137
138
  - lib/rollbar/delayed_job.rb
138
139
  - lib/rollbar/exception_reporter.rb
139
140
  - lib/rollbar/goalie.rb