rollbar 2.16.0 → 2.16.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11bd20d68ff24396b75b8518ea2ffbe641cfd8fc
4
- data.tar.gz: c3838b31c21856ad31abe72f82b96edeff3a8eda
3
+ metadata.gz: ef98d47074226584e6ee894d82f5a3d0c73664c9
4
+ data.tar.gz: c01e80f38136f5397bb1c585fa8d31c803dee8cd
5
5
  SHA512:
6
- metadata.gz: 9ea80cb9c0b5d102bdd16b784e531efbb7c74ba771da22a63d64d2b34c8ada1dec0ad95db2974267ec33c6cee4ad49c24450b39f4c1859391ab8483aa6dd7efd
7
- data.tar.gz: ac2f51581aeca7f5af213f79651a1123e4e8a5810ac9bf8e6298b05cb57bf205de773246b717d554ace0b42d02b8a4aa3e0e14d78a9d9a6555d0351f3ec2104f
6
+ metadata.gz: 25a0bcec30eef59e718bad1d5857612c8938df5be9afec3b7c20251f93d11abd50f265ef1284f249202eec9d308a01ae867c737e83c86451e7bd0af717a34b71
7
+ data.tar.gz: a0958ba5221c0184067b90e5aff2aa160c97d607084984a405f63542701cca7a548dc72aec5e713b613e532d3a17d28acfc65cac08cac05d85a5a655391caa03
data/.gitignore CHANGED
@@ -23,4 +23,6 @@ tmp
23
23
  .ruby-version
24
24
  .byebug_history
25
25
 
26
- gemfiles/vendor
26
+ gemfiles/vendor
27
+
28
+ vendor
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.16.0 and above
4
+
5
+ For changes in version 2.16 and above, the change log has moved to this repo's [GitHub Releases Page](https://github.com/rollbar/rollbar-gem/releases)
6
+
3
7
  ## 2.15.6
4
8
  - Update rollbar.js snippet to `v2.3.8` [#680](https://github.com/rollbar/rollbar-gem/issues/680)
5
9
  - Update `delayed_job` dependency to `4.1.3` [#672](https://github.com/rollbar/rollbar-gem/issues/672)
data/README.md CHANGED
@@ -1,1200 +1,27 @@
1
- # Rollbar [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=master)](https://travis-ci.org/rollbar/rollbar-gem/branches)
1
+ # Rollbar-gem
2
+ [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=master)](https://travis-ci.org/rollbar/rollbar-gem/branches)
2
3
 
3
- <!-- RemoveNext -->
4
- [Rollbar](https://rollbar.com) is an error tracking service for Ruby and other languages. The Rollbar service will alert you of problems with your code and help you understand them in a ways never possible before. We love it and we hope you will too.
4
+ [Rollbar](https://rollbar.com) is a real-time exception reporting service for Ruby and other languages. The Rollbar service will alert you of problems with your code and help you understand them in a ways never possible before. We love it and we hope you will too.
5
5
 
6
- This is the Ruby library for Rollbar. It will instrument many kinds of Ruby applications automatically at the framework level. You can also make direct calls to send exceptions and messages to Rollbar.
6
+ Rollbar-gem is the SDK for Ruby apps and includes support for apps using Rails, Sinatra, Rack, plain Ruby, and other frameworks.
7
7
 
8
- <!-- Sub:[TOC] -->
8
+ ## Setup Instructions
9
9
 
10
- ## Getting Started
10
+ 1. [Sign up for a Rollbar account](https://rollbar.com/signup)
11
+ 2. Follow the [Getting Started](https://docs.rollbar.com/docs/ruby#section-getting-started) instructions in our [Ruby SDK docs](https://docs.rollbar.com/docs/ruby) to install rollbar-gem and configure it for your platform.
11
12
 
12
- Add this line to your application's Gemfile:
13
+ ## Usage and Reference
13
14
 
14
- ```ruby
15
- gem 'rollbar'
16
- ```
17
-
18
- And then execute:
19
-
20
- ```bash
21
- $ bundle install
22
- # Or if you don't use bundler:
23
- $ gem install rollbar
24
- ```
25
-
26
- Unless you are using JRuby, we suggest also installing [Oj](https://github.com/ohler55/oj) for JSON serialization. Add this line to your Gemfile:
27
-
28
- ```ruby
29
- gem 'oj', '~> 2.16.1'
30
- ```
31
-
32
- and then `bundle install` again.
33
-
34
- ### Rails
35
-
36
- Run the following command from your Rails root:
37
-
38
- ```bash
39
- $ rails generate rollbar POST_SERVER_ITEM_ACCESS_TOKEN
40
- ```
41
-
42
- <!-- RemoveNextIfProject -->
43
- Be sure to replace ```POST_SERVER_ITEM_ACCESS_TOKEN``` with your project's ```post_server_item``` access token, which you can find in the Rollbar.com interface.
44
-
45
- That will create the file ```config/initializers/rollbar.rb```, which initializes Rollbar and holds your access token and other configuration values.
46
-
47
- If you want to store your access token outside of your repo, run the same command without arguments and create an environment variable ```ROLLBAR_ACCESS_TOKEN``` that holds your server-side access token:
48
-
49
- ```bash
50
- $ rails generate rollbar
51
- $ export ROLLBAR_ACCESS_TOKEN=POST_SERVER_ITEM_ACCESS_TOKEN
52
- ```
53
-
54
- For Heroku users:
55
-
56
- If you're on Heroku, you can store the access token in your Heroku config:
57
-
58
- ```bash
59
- $ heroku config:add ROLLBAR_ACCESS_TOKEN=POST_SERVER_ITEM_ACCESS_TOKEN
60
- ```
61
-
62
- That's all you need to use Rollbar with Rails.
63
-
64
- #### Grape
65
-
66
- To capture 500s inside the API gem "Grape" for Rails applications, add the following as a global exception handler:
67
-
68
- ```ruby
69
- rescue_from :all do |e|
70
- if Rails.env.development?
71
- raise e
72
- else
73
- Rollbar.error(e)
74
- error_response(message: "Internal server error", status: 500)
75
- end
76
- end
77
- ```
78
-
79
-
80
- ### Sinatra
81
-
82
- Initialize Rollbar with your access token somewhere during startup:
83
-
84
- ```ruby
85
- Rollbar.configure do |config|
86
- config.access_token = 'POST_SERVER_ITEM_ACCESS_TOKEN'
87
- # other configuration settings
88
- # ...
89
- end
90
- ```
91
-
92
- Then mount the middleware in your app, like:
93
-
94
- ```ruby
95
- require 'rollbar/middleware/sinatra'
96
-
97
- class MyApp < Sinatra::Base
98
- use Rollbar::Middleware::Sinatra
99
- # other middleware/etc
100
- # ...
101
- end
102
- ```
103
- #### Note
104
- There is a known conflict between Sinatra and other gems where Sinatra's top-level-binded methods get overriden by other gems (more details here: https://github.com/sinatra/sinatra-contrib/issues/111 and https://github.com/rollbar/rollbar-gem/issues/663). This came to attention when using `sinatra/namespace` and `Rollbar.configure`. If your top-level-binded methods get overshadowed by other gems, like `Rake::DSL.namespace`, you will need to redefine the method manually as intended by Sinatra.
105
-
106
- Here is an example if you want to use `sinatra/namespace`:
107
-
108
- ```ruby
109
- configure do
110
- Rollbar.configure do |config|
111
- ...
112
- end
15
+ For complete usage instructions and configuration reference, see our [Ruby SDK docs](https://docs.rollbar.com/docs/ruby).
113
16
 
114
- # Redefine :namespace to use Sinatra's :namespace method
115
- self.instance_eval do
116
- undef :namespace
117
-
118
- define_singleton_method(:namespace) do |*args, &block|
119
- Sinatra::Delegator.target.send(:namespace, *args, &block)
120
- end
121
- end
122
- end
123
- ```
124
-
125
- ### Rack
126
-
127
- Initialize Rollbar with your access token somewhere during startup:
128
-
129
- ```ruby
130
- Rollbar.configure do |config|
131
- config.access_token = 'POST_SERVER_ITEM_ACCESS_TOKEN'
132
- # other configuration settings
133
- # ...
134
- end
135
- ```
136
-
137
- <!-- RemoveNextIfProject -->
138
- Be sure to replace ```POST_SERVER_ITEM_ACCESS_TOKEN``` with your project's ```post_server_item``` access token, which you can find in the Rollbar.com interface.
139
-
140
- The gem monkey patches `Rack::Builder` so Rollbar reports will be sent automatically without any other action. If you prefer to disable the monkey patch apply this change to your config:
141
-
142
- ```ruby
143
- Rollbar.configure do |config|
144
- config.disable_rack_monkey_patch = true
145
- # other configuration settings
146
- # ...
147
- end
148
- ```
149
-
150
- If you disabled the `Rack::Builder` monkey patch or it doesn't work for the Rack framework you are using, then add our Rack middleware to your app:
151
-
152
- ```ruby
153
- require 'rollbar/middleware/rack'
154
-
155
- use Rollbar::Middleware::Rack
156
- ```
157
-
158
- ### Plain Ruby
159
-
160
- Rollbar isn't dependent on Rack or Rails for most of its functionality. In a regular script, assuming you've
161
- installed the rollbar gem:
162
-
163
- 1. Require rollbar
164
- 2. Configure rollbar
165
- 3. Send Rollbar data
166
-
167
- ```ruby
168
- require 'rollbar'
169
-
170
- Rollbar.configure do |config|
171
- config.access_token = "POST_SERVER_ITEM_ACCESS_TOKEN"
172
- # Other Configuration Settings
173
- end
174
-
175
- Rollbar.debug("Running Script")
176
-
177
- begin
178
- run_script ARGV
179
- rescue Exception => e # Never rescue Exception *unless* you re-raise in rescue body
180
- Rollbar.error(e)
181
- raise e
182
- end
183
-
184
- Rollbar.info("Script ran successfully")
185
- ```
186
-
187
-
188
- ## Integration with Rollbar.js
189
-
190
- In case you want to report your JavaScript errors using [Rollbar.js](https://github.com/rollbar/rollbar.js), you can configure the gem to enable Rollbar.js on your site. Example:
191
-
192
- ```ruby
193
- Rollbar.configure do |config|
194
- # common gem configuration
195
- # ...
196
- config.js_enabled = true
197
- config.js_options = {
198
- accessToken: "POST_CLIENT_ITEM_ACCESS_TOKEN",
199
- captureUncaught: true,
200
- payload: {
201
- environment: "production"
202
- }
203
- }
204
- end
205
- ```
206
-
207
- The `Hash` passed to `#js_options=` should have the same available options that you can find in [Rollbar.js](https://github.com/rollbar/rollbar.js), using symbols or strings for the keys.
208
-
209
- ## Test your installation
210
-
211
- If you're not using Rails, you may first need to add the following to your Rakefile:
212
-
213
- ```ruby
214
- require 'rollbar/rake_tasks'
215
- ```
216
-
217
- You may also need to add an `:environment` task to your Rakefile if you haven't already defined one. At a bare minimum, this task should call `Rollbar.configure()` and set your access token.
218
-
219
- ```ruby
220
- task :environment do
221
- Rollbar.configure do |config |
222
- config.access_token = '...'
223
- end
224
- end
225
- ```
226
-
227
- To confirm that it worked, run:
228
-
229
- ```bash
230
- $ rake rollbar:test
231
- ```
232
-
233
- 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.
234
-
235
- ## Usage
236
-
237
- ### Uncaught exceptions
238
-
239
- Uncaught exceptions in Rails controllers will be automatically reported to Rollbar.
240
-
241
- ### Caught exceptions and messages
242
-
243
- You can use one of `Rollbar.log(level, ...)`, `Rollbar.debug()`, `Rollbar.info()`, `Rollbar.warning()`, `Rollbar.error()` and `Rollbar.critical()` to report exceptions and messages.
244
-
245
- The methods accept any number of arguments. The last exception is used as the reported exception, the last string is used as the message/description, and the last hash is used as the extra data.
246
-
247
- For example:
248
-
249
- ```ruby
250
- begin
251
- result = user_info[:key1][:key2][:key3]
252
- rescue NoMethodError => e
253
- # simple exception report (level can be 'debug', 'info', 'warning', 'error' and 'critical')
254
- Rollbar.log('error', e)
255
-
256
- # same functionality as above
257
- Rollbar.error(e)
258
-
259
- # with a description
260
- Rollbar.error(e, 'The user info hash doesn\'t contain the correct data')
261
-
262
- # with extra data giving more insight about the exception
263
- Rollbar.error(e, :user_info => user_info, :job_id => job_id)
264
- end
265
- ```
266
-
267
- You can also log individual messages:
268
-
269
- ```ruby
270
- Rollbar.warning('Unexpected input')
271
-
272
- # can also include extra data
273
- Rollbar.info("Login successful", :username => @username)
274
-
275
- Rollbar.log('debug', 'Settings saved', :account_id => account.id)
276
- ```
277
-
278
- ### Reporting form validation errors
279
-
280
- To get form validation errors automatically reported to Rollbar just add the following ```after_validation``` callback to your models:
281
-
282
- ```ruby
283
- after_validation :report_validation_errors_to_rollbar
284
- ```
285
-
286
- ### Advanced usage
287
-
288
- You can use `Rollbar.scope()` to copy a notifier instance and customize the payload data for one-off reporting. The hash argument to `scope()` will be merged into the copied notifier's "payload options", a hash that will be merged into the final payload just before it is reported to Rollbar.
289
-
290
- For example:
291
-
292
- ```ruby
293
- while job
294
- user = job.user
295
-
296
- # Overwrites any existing person data
297
- notifier = Rollbar.scope({
298
- :person => {:id => user.id, :username => user.username, :email => user.email}
299
- })
300
-
301
- begin
302
- job.do_work
303
- rescue => e
304
- # Sends a report with the above person data
305
- notifier.critical(e)
306
- end
307
-
308
- job = next_job
309
- end
310
-
311
- # Wipe person data
312
- notifier = notifier.scope({
313
- :person => nil
314
- })
315
-
316
- # No associated person data
317
- notifier.info('Jobs processed')
318
- ```
319
-
320
- If you don't want to work with a new `Notifier` instance `.scoped` will do it for you:
321
-
322
- ```ruby
323
- while job
324
- user = job.user
325
-
326
- # Overwrites any existing person data
327
- scope = {
328
- :person => {:id => user.id, :username => user.username, :email => user.email}
329
- }
330
-
331
- Rollbar.scoped(scope) do
332
- begin
333
- job.do_work
334
- rescue => e
335
- # Sends a report with the above person data
336
- Rollbar.critical(e)
337
- end
338
- end
339
-
340
- job = next_job
341
- end
342
- ```
343
-
344
- To modify the current scope (rather than creating a new one), use `Rollbar.scope!`. You can use this to add additional context data from inside a web request, background job, etc.
345
-
346
- ```ruby
347
- class NotificationJob
348
- include Sidekiq::Worker
349
-
350
- def perform(user_id)
351
- Rollbar.scope!(:person => { :id => user_id })
352
-
353
- # If this next line causes an exception, the reported exception (which will
354
- # be reported by Rollbar's standard Sidekiq instrumentation) will also
355
- # include the above person information.
356
- Notification.send_to_user(user_id)
357
- end
358
- end
359
- ```
360
-
361
- Note: if you are using `Rollbar.scope!` within a scoped block, your context will only apply within that scoped block because of how Rollbar gets shadowed.
362
-
363
- ## Person tracking
364
-
365
- 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.
366
-
367
- This will happen automatically for uncaught Rails exceptions and for any manual exception or log reporting done within a Rails request.
368
-
369
- If the gem should call a controller method besides ```current_user```, add the following in ```config/initializers/rollbar.rb```:
370
-
371
- ```ruby
372
- Rollbar.configure do |config|
373
- config.person_method = "my_current_user"
374
- end
375
- ```
376
-
377
- 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```:
378
-
379
- ```ruby
380
- Rollbar.configure do |config|
381
- config.person_id_method = "user_id" # default is "id"
382
- config.person_username_method = "user_name" # default is `nil`
383
- config.person_email_method = "email_address" # default is `nil`
384
- end
385
- ```
386
-
387
- ### Person tracking with Rack applications
388
-
389
- To track information about the current user in non-Rails applications, you can populate the `rollbar.person_data` key in the Rack environment with the desired data. Its value should be a hash like:
390
-
391
- ```ruby
392
- {
393
- :id => "123", # required; string up to 40 characters
394
- :username => "adalovelace", # optional; string up to 255 characters
395
- :email => "ada@lovelace.net" # optional; string up to 255 characters
396
- }
397
- ```
398
-
399
- Because Rack applications can vary so widely, we don't provide a default implementation in the gem, but here is an example middleware:
400
-
401
- ```ruby
402
- class RollbarPersonData
403
- def initialize(app)
404
- @app = app
405
- end
406
-
407
- def call(env)
408
- token = Rack::Request.new(env).params['token']
409
- user = User.find_by_token(token)
410
-
411
- if user
412
- env['rollbar.person_data'] = extract_person_data(user)
413
- end
414
-
415
- @app.call(env)
416
- end
417
-
418
- def extract_person_data(user)
419
- {
420
- id: user.id,
421
- username: user.username,
422
- email: user.email
423
- }
424
- end
425
- end
426
-
427
- # You can add the middleware to your application, for example:
428
-
429
- require 'rollbar/middleware/sinatra'
430
-
431
- class App < Sinatra::Base
432
- use Rollbar::Middleware::Sinatra
433
- use RollbarPersonData
434
-
435
- # ...
436
- # ...
437
- end
438
- ```
439
-
440
- ## Special note about reporting within a request
441
-
442
- The gem instantiates one `Notifier` instance on initialization, which will be the base notifier that is used for all reporting (via a `method_missing` proxy in the `Rollbar` module). Calling `Rollbar.configure()` will configure this base notifier that will be used globally in a ruby app.
443
-
444
- However, the Rails middleware will actually scope this base notifier for use within a request by storing it in thread-local storage (see [here](https://github.com/rollbar/rollbar-gem/blob/5f4e6135f0e61148672b0190c88767aa52e5cdb3/lib/rollbar/middleware/rails/rollbar.rb#L35-L39)). This is done to make any manual logging within a request automatically contain request and person data. Calling `Rollbar.configure()` therefore will only affect the notifier for the duration of the request, and not the base notifier used globally.
445
-
446
- ## Data sanitization (scrubbing)
447
-
448
- By default, the notifier will "scrub" the following fields from payloads before sending to Rollbar
449
-
450
- - ```:passwd```
451
- - ```:password```
452
- - ```:password_confirmation```
453
- - ```:secret```
454
- - ```:confirm_password```
455
- - ```:secret_token```
456
-
457
- And the following http header
458
-
459
- - ```"Authorization"```
460
-
461
- If a request contains one of these fields, the value will be replaced with a ```"*"``` before being sent.
462
-
463
- Additional params can be scrubbed by updating ```config.scrub_fields```:
464
-
465
- ```ruby
466
- # scrub out the "user_password" field
467
- config.scrub_fields |= [:user_password]
468
- ```
469
-
470
- And ```config.scrub_headers```:
471
-
472
- ```ruby
473
- # scrub out the "X-Access-Token" http header
474
- config.scrub_headers |= ["X-Access-Token"]
475
- ```
476
-
477
- If you want to obfuscate the user IP reported to the Rollbar API you can configure a secret to do it and a different IP address from the original will be reported:
478
-
479
- ```
480
- Rollbar.configuration.user_ip_obfuscator_secret = "a-private-secret-here"
481
- ```
482
-
483
- The fields in `scrub_fields` will be used to scrub the values for the matching keys in the GET, POST, raw body and route params and also in cookies and session. If you want to customize better exactly which part of the request data is scrubbed you can use the [Transform hook](#transform-hook).
484
-
485
- Example:
486
-
487
- ```
488
- config.transform << proc do |options|
489
- data = options[:payload]['data']
490
- data[:request][:session][:key] = Rollbar::Scrubbers.scrub_value(data[:request][:session][:key])
491
- end
492
- ```
493
-
494
- In the previous example we are scrubbing the `key` value inside the session data.
495
-
496
- If you would simply like to scrub all params, you can use `:scrub_all` like so:
497
-
498
- ```
499
- config.scrub_fields = :scrub_all
500
- ```
501
-
502
-
503
- ## Including additional runtime data
504
-
505
- You can provide a callable that will be called for each exception or message report. ```custom_data_method``` should be a lambda that either takes no arguments or takes three arguments (message, exception, context) and returns a hash.
506
-
507
- Add the following in ```config/initializers/rollbar.rb```:
508
-
509
- ```ruby
510
- config.custom_data_method = lambda {
511
- { :some_key => :some_value, :complex_key => {:a => 1, :b => [2, 3, 4]} }
512
- }
513
- ```
514
-
515
- Or
516
-
517
- ```ruby
518
- config.custom_data_method = lambda{ |message, exception, context|
519
- { :some_key => :some_value, :complex_key => {:a => 1, :b => [2, 3, 4]} }
520
- }
521
- ```
522
-
523
- This data will appear in the Occurrences tab and on the Occurrence Detail pages in the Rollbar interface.
524
-
525
- If your `custom_data_method` crashes while reporting an error, Rollbar will report that new error and will attach its uuid URL to the parent error report.
526
-
527
- `context` for your `custom_data_method` is the value passed in the `:custom_data_method_context` key of your `log` method's `extra_data` argument. Note that once the value is passed as `context` it is removed from your `extra_data` and will be not be included in your `extra` by default.
528
-
529
- ```ruby
530
- config.custom_data_method = lambda { |message, exception, context|
531
- {
532
- fully_qualified_controller_name: "MyApp::" + context[:controller_name]
533
- }
534
- }
535
-
536
- Rollbar.log(
537
- "error",
538
- "Simple message",
539
- {
540
- extra_data_1: "some value",
541
- custom_data_method_context: {
542
- controller_name: "ExampleController"
543
- }
544
- }
545
- )
546
- ```
547
-
548
- The above example will result in the following `extra`:
549
-
550
- ```ruby
551
- {
552
- extra_data_1: "some value",
553
- fully_qualified_controller_name: "MyApp::ExampleController"
554
- }
555
- ```
556
-
557
- As you can see, the `custom_data_method_context` will not be directly included in your `extra`.
558
-
559
- Below is an example usage in a Rails application:
560
-
561
- ```ruby
562
- # config/initializers/rollbar.rb
563
- Rollbar.configure do |config|
564
- ...
565
-
566
- config.custom_data_method = lambda do |message, exception, context|
567
- { controller_name: context[:controller].controller_name }
568
- end
569
- end
570
- ```
571
-
572
- ```ruby
573
- # app/controller/welcome_controller.rb
574
- class WelcomeController < ApplicationController
575
- def check_context
576
- Rollbar.log(
577
- 'info',
578
- 'This is a message from Welcome#check_context',
579
- {
580
- custom_data_method_context: {
581
- controller: self
582
- }
583
- }
584
- )
585
- end
586
- end
587
- ```
588
-
589
- ## Exception level filters
590
-
591
- By default, all uncaught exceptions are reported at the "error" level, except for the following, which are reported at "warning" level:
592
-
593
- - ```ActiveRecord::RecordNotFound```
594
- - ```AbstractController::ActionNotFound```
595
- - ```ActionController::RoutingError```
596
-
597
- If you'd like to customize this list, modify 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. For example, to ignore 404s and treat `NoMethodError`s as critical bugs, you can use the following code:
598
-
599
- ```ruby
600
- config.exception_level_filters.merge!({
601
- 'ActionController::RoutingError' => 'ignore',
602
- 'NoMethodError' => 'critical'
603
- })
604
- ```
605
-
606
- This behavior applies to uncaught exceptions, not direct calls to `Rollbar.error()`, `Rollbar.warning()`, etc. If you are making a direct call to one of the log methods and want exception level filters to apply, pass an extra keyword argument:
607
-
608
- ```ruby
609
- Rollbar.error(exception, :use_exception_level_filters => true)
610
- ```
611
-
612
- ### Dynamic levels
613
-
614
- You can also specify a callable object (any object that responds to `call`) which will be called with the exception instance. For example, you can have a single error reported at different levels using the following code:
615
-
616
- ```ruby
617
- config.exception_level_filters.merge!({
618
- 'SomeError' => lambda { |error| error.to_s.include?('not serious enough') ? 'info' : 'error' }
619
- })
620
- ```
621
-
622
- ## Before process hook
623
-
624
- Before we process data sent to Rollbar.log (or Rollbar.error/info/etc.) to build and send the payload, the gem will call the handlers defined in `configuration.before_process`. This handlers should be `Proc` objects or objects responding to `#call` method. The received argument is a `Hash` object with these keys:
625
-
626
- - `level`: the level used for the report.
627
- - `exception`: the exception that caused the report, if any.
628
- - `message`: the message to use for the report, if any.
629
- - `extra`: extra data passed to the report methods.
630
- - `scope`: the current Scope; see [Scope](#the-scope)
631
-
632
- If the exception `Rollbar::Ignore` is raised inside any of the handlers defined for `configuration.before_process`, we'll ignore the report and not send it to the API. For example:
633
-
634
- ```ruby
635
- handler = proc do |options|
636
- raise Rollbar::Ignore if any_smart_method(options)
637
- end
638
-
639
- Rollbar.configure do |config|
640
- config.before_process << handler
641
- end
642
- ```
643
-
644
- ## Transform hook
645
-
646
- After the payload is built but before it it sent to our API, the gem will call the handlers defined in `configuration.transform`. This handlers should be `Proc` objects or objects responding to `#call` method. The received argument is a `Hash` object with these keys:
647
-
648
- - `level`: the level used for the report.
649
- - `exception`: the exception that caused the report, if any.
650
- - `message`: the message to use for the report, if any.
651
- - `extra`: extra data passed to the report methods.
652
- - `scope`: the current Scope; see [Scope](#the-scope)
653
- - `payload`: the built payload that will be sent to the API
654
-
655
- Handlers may mutate the payload. For example:
17
+ ## Release History & Changelog
656
18
 
657
- ```ruby
658
- handler = proc do |options|
659
- payload = options[:payload]
660
-
661
- payload['data']['environment'] = 'foo'
662
- end
663
-
664
- Rollbar.configure do |config|
665
- config.transform << handler
666
- end
667
- ```
668
-
669
- ## The Scope
670
-
671
- The scope an object, an instance of `Rollbar::LazyStore` that stores the current context data for a certain moment or situation. For example, the Rails middleware defines the scope in a way similar to this:
672
-
673
- ```ruby
674
- scope = {request: request_data,
675
- person: person_data,
676
- context: context_data
677
- }
678
- Rollbar.scoped(scope) do
679
- begin
680
- @app.call(env)
681
- rescue Exception => exception
682
- # ...
683
- end
684
- end
685
-
686
- ```
687
-
688
- You can access the scope on the [before_process](#before-process-hook) and [transform](#transform-hook) hooks like this:
689
-
690
- ```ruby
691
- your_handler = proc do |options|
692
- scope = options[:scope]
693
-
694
- request_data = scope[:request]
695
- person_data = scope[:person]
696
- context_data = scope[:context]
697
- end
698
- ```
699
-
700
- ## Override configuration
701
-
702
- There are some cases where you would need to change the Rollbar configuration for a specific block of code so a new configuration is used on the reported errors in that block. You can use `Rollbar.with_config` to do this. It receives a `Hash` object with the configuration overrides you want to use for the given block. The configuration options to use can be read at [Configuration](https://rollbar.com/docs/notifier/rollbar-gem/configuration/). So the `Hash` passed to `with_config` can be like `{environment: 'specific-environment'}`. Example:
703
-
704
- ```ruby
705
- Rollbar.with_config(use_async: false) do
706
- begin
707
- # do work that may crash
708
- rescue => e
709
- Rollbar.error(e)
710
- end
711
- end
712
- ```
713
-
714
- This method looks similar to `Rollbar.scoped` and internally `Rollbar.with_config` uses it. Now `Rollbar.scoped` can receive a second argument with the config overrides for the given block of code. So if you need to set a new payload scope and new config for a code block, you can:
715
-
716
- ```ruby
717
- scope = {context: 'foo'}
718
- new_config = {framework: 'Sinatra'}
719
-
720
- Rollbar.scoped(scope, new_config) do
721
- begin
722
- # do work that may crash
723
- rescue => e
724
- Rollbar.error(e)
725
- end
726
- end
727
- ```
728
-
729
- In the example from above we are defining a new payload scope and overriding the `framework` configuration for the reported errors inside the given block.
730
-
731
- ## Code and context
732
-
733
- By default we send the following values for each backtrace frame: `filename`, `lineno` and `method`. You can configure Rollbar to additionally send `code` (the actual line of code) and `context` (lines before and after) for each frame.
734
-
735
- Since the backtrace can be very long, you can configure to send this data for all the frames or only your in-project frames. There are three levels: `:none` (default), `:app` (only your project files) and `:all`. Example:
736
-
737
- ```ruby
738
- Rollbar.configure do |config|
739
- config.send_extra_frame_data = :app
740
- end
741
- ```
742
-
743
- ## Silencing exceptions at runtime
744
-
745
- If you just want to disable exception reporting for a single block, use ```Rollbar.silenced```:
746
-
747
- ```ruby
748
- Rollbar.silenced {
749
- foo = bar # will not be reported
750
- }
751
- ```
752
-
753
- ## Sending backtrace without rescued exceptions
754
-
755
- If you use the gem in this way:
756
-
757
- ```ruby
758
- exception = MyException.new('this is a message')
759
- Rollbar.error(exception)
760
- ```
761
-
762
- You will notice a backtrace doesn't appear in your Rollbar dashboard. This is because `exception.backtrace` is `nil` in these cases. We can send the current backtrace for you even if your exception doesn't have it. In order to enable this feature you should configure Rollbar in this way:
763
-
764
- ```ruby
765
- Rollbar.configure do |config|
766
- config.populate_empty_backtraces = true
767
- end
768
- ```
769
-
770
- ## ActiveJob integration
771
-
772
- Include the module `Rollbar::ActiveJob` in you jobs to report any uncaught errors in a job to Rollbar.
773
-
774
- ```ruby
775
- class YourAwesomeJob < ActiveJob::Base
776
- include Rollbar::ActiveJob
777
- end
778
- ```
779
-
780
- If you need to customize the reporting write your own `rescue_from` handler instead of using the `Rollbar::ActiveJob` module.
781
-
782
- Note: If you're using Sidekiq and integrate ActiveJob, you may get double reports of background job errors in Rollbar. The way to avoid this is to rely on the Sidekiq error handling, not ActiveJob in this case.
783
-
784
- ## Delayed::Job
785
-
786
- If `delayed_job` is defined, Rollbar will automatically install a plugin that reports any uncaught exceptions that occur in jobs.
787
-
788
- By default, the job's data will be included in the report. If you want to disable this functionality to prevent sensitive data from possibly being sent, use the following configuration option:
789
-
790
- ```ruby
791
- config.report_dj_data = false # default is true
792
- ```
793
-
794
- You can also change the threshold of job retries that must occur before a job is reported to Rollbar:
795
-
796
- ```ruby
797
- config.dj_threshold = 2 # default is 0
798
- ```
799
-
800
- If you use [custom jobs](https://github.com/collectiveidea/delayed_job#custom-jobs) that define their own hooks to report exceptions, please consider disabling our plugin. Not doing so will result in duplicate exceptions being reported as well as lack of control when exceptions should be reported. To disable our Delayed::Job plugin, add the following line after the `Rollbar.configure` block.
801
-
802
- ```ruby
803
- config.delayed_job_enabled = false
804
- ```
805
-
806
- Only versions >= 3.0 of delayed_job are supported.
807
-
808
-
809
- ## Asynchronous reporting
810
-
811
- By default, all messages are reported synchronously. You can enable asynchronous reporting with [girl_friday](https://github.com/mperham/girl_friday), [sucker_punch](https://github.com/brandonhilkert/sucker_punch), [Sidekiq](https://github.com/mperham/sidekiq), [Resque](https://github.com/resque/resque), [DelayedJob](https://github.com/collectiveidea/delayed_job) or using threading.
812
-
813
- ### girl_friday
814
-
815
- Add the following in ```config/initializers/rollbar.rb```:
816
-
817
- ```ruby
818
- config.use_async = true
819
- ```
820
-
821
- Asynchronous reporting falls back to Threading if girl_friday is not installed.
822
-
823
- ### sucker_punch
824
-
825
- Add the following in ```config/initializers/rollbar.rb```:
826
-
827
- ```ruby
828
- config.use_sucker_punch
829
- ```
830
-
831
- ### Sidekiq
832
-
833
- Add the following in ```config/initializers/rollbar.rb```:
834
-
835
- ```ruby
836
- config.use_sidekiq
837
- ```
838
-
839
-
840
- The default Sidekiq queue will be `rollbar` but you can also supply custom Sidekiq options:
841
-
842
- ```ruby
843
- config.use_sidekiq 'queue' => 'default'
844
- ```
845
-
846
- You also need to add the name of the queue to your `sidekiq.yml`
847
-
848
- ```
849
- :queues:
850
- - default
851
- - rollbar
852
- ```
853
-
854
- Start the redis server:
855
-
856
- ```bash
857
- $ redis-server
858
- ```
859
-
860
- 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":
861
-
862
- ```bash
863
- $ bundle exec sidekiq -q rollbar
864
- ```
865
-
866
- For every errored job a new report will be sent to Rollbar API, also for errored retried jobs. You can configure the retries threshold to start reporting to rollbar:
867
-
868
- ```ruby
869
- config.sidekiq_threshold = 3 # Start reporting from 3 retries jobs
870
- ```
871
-
872
- ### Shoryuken
873
-
874
- Add the following in ```config/initializers/rollbar.rb```
875
-
876
- ```ruby
877
- config.environment = Rails.env # necessary for building proper SQS name.
878
- config.use_shoryuken
879
- ```
880
-
881
- You also need to have the configuration for shoryuken in you project `shoryuken.yml` and AWS settings, or, at least:
882
- ```ruby
883
- ENV['AWS_ACCESS_KEY_ID'] = 'xxx'
884
- ENV['AWS_SECRET_ACCESS_KEY'] = 'xxx'
885
- ENV['AWS_REGION'] = 'xxx'
886
- ```
887
- Read more about [Shoryuken configuration](https://github.com/phstc/shoryuken/wiki/Shoryuken-options).
888
-
889
- Also create the SQS channels equals to your environments, as follows:
890
- The queues to report will be equal to ```rollbar_{CURRENT_ENVIRONMENT}``` ex: if the project runs in staging environment the SQS to throw messages to will be equal to ```rollbar_staging```
891
- At this stage, you are unable to set custom SQS name to use.
892
-
893
- ### Resque
894
-
895
- Add the following in ```config/initializers/rollbar.rb```:
896
-
897
- ```ruby
898
- config.use_resque
899
- ```
900
-
901
- You can also supply a custom Resque queue:
902
-
903
- ```ruby
904
- config.use_resque :queue => 'my_queue'
905
- ```
906
-
907
- Now you can just start a new Resque worker processing jobs in that queue:
908
-
909
- ```bash
910
- $ QUEUE=my_queue bundle exec resque:work
911
- ```
912
-
913
- ### DelayedJob
914
-
915
- Add the following in ```config/initializers/rollbar.rb```:
916
-
917
- ```ruby
918
- config.use_delayed_job
919
- ```
920
-
921
- By default, an unnamed queue is used for processing jobs. If you wish to use a named queue, as
922
- [described here](https://github.com/collectiveidea/delayed_job#named-queues), pass the name of the
923
- queue as an option in the configuraton:
924
-
925
- ```ruby
926
- config.use_delayed_job :queue => 'my_queue'
927
- ```
928
-
929
-
930
- ### Threading
931
-
932
- Add the following in ```config/initializers/rollbar.rb```:
933
-
934
- ```ruby
935
- config.use_thread
936
- ```
937
-
938
- ### Other handlers
939
-
940
- You can supply your own handler using ```config.async_handler```. The object to set for `async_handler` should respond to `#call` and receive the payload. 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:
941
-
942
- ```ruby
943
- config.use_async = true
944
- config.async_handler = Proc.new { |payload|
945
- Thread.new { Rollbar.process_from_async_handler(payload) }
946
- }
947
- ```
948
-
949
- Make sure you pass ```payload``` to ```Rollbar.process_from_async_handler``` in your own implementation.
950
-
951
- ### Failover handlers
952
-
953
- If you are using `async_handler` to process asynchronous the error it's possible that the handler fails before it calls `Rollbar.process_payload`. For example, for the Resque handler, the Redis connection could fail so the job is finally not processed.
954
-
955
- To ensure that the error is sent you can define a chain of failover handlers that Rollbar will use to send the payload in case that the primary handler fails. The failover handlers, as for `async_handler`, are just objects responding to `#call`.
956
-
957
- To configure the failover handlers you can add the following:
958
-
959
- ```ruby
960
- config.use_resque
961
- config.failover_handlers = [Rollbar::Delay::GirlFriday, Rollbar::Delay::Thread]
962
- ```
963
-
964
- With the configuration above Resque will be your primary asynchronous handler but if it fails queueing the job Rollbar will use GirlFriday at first, and just a thread in case that GirlFriday fails too.
965
-
966
- ## Logger interface
967
-
968
- The gem provides a class `Rollbar::Logger` that inherits from `Logger` so you can use Rollbar to log your application messages. The basic usage is:
969
-
970
- ```ruby
971
- require 'rollbar/logger'
972
-
973
- logger = Rollbar::Logger.new
974
- logger.info('Purchase failed!')
975
- ```
976
-
977
- If you are using Rails you can extend your `Rails.logger` so the log messages are sent to both outputs. You can use this snippet in one initializer (for example, `config/initializers/rollbar.rb`):
978
-
979
- ```ruby
980
- require 'rollbar/logger'
981
-
982
- Rails.logger.extend(ActiveSupport::Logger.broadcast(Rollbar::Logger.new))
983
- ```
984
-
985
- ## Using with rollbar-agent
986
-
987
- 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```:
988
-
989
- ```ruby
990
- config.write_to_file = true
991
- # optional, defaults to "#{AppName}.rollbar"
992
- config.filepath = '/path/to/file.rollbar' #should end in '.rollbar' for use with rollbar-agent
993
- ```
994
-
995
- For this to work, you'll also need to set up rollbar-agent--see its docs for details.
996
-
997
- ## Rails booting process
998
-
999
- Rails doesn't provide a way to hook into its booting process, so we can't catch errors during boot out of the box. To report these errors to Rollbar, make the following changes to your project files.
1000
-
1001
- First, move your `config/initializers/rollbar.rb` file to `config/rollbar.rb`. Then be sure your `config/environment.rb` looks similar to this:
1002
-
1003
- ```ruby
1004
- # config/environment.rb
1005
-
1006
- require File.expand_path('../application', __FILE__)
1007
- require File.expand_path('../rollbar', __FILE__)
1008
-
1009
- notify = ->(e) do
1010
- begin
1011
- Rollbar.with_config(use_async: false) do
1012
- Rollbar.error(e)
1013
- end
1014
- rescue
1015
- Rails.logger.error "Synchronous Rollbar notification failed. Sending async to preserve info"
1016
- Rollbar.error(e)
1017
- end
1018
- end
1019
-
1020
- begin
1021
- Rails.application.initialize!
1022
- rescue Exception => e
1023
- notify.(e)
1024
- raise
1025
- end
1026
- ```
1027
-
1028
- How this works: first, Rollbar config (which is now at `config/rollbar.rb` is required). Later, `Rails.application/initialize` statement is wrapped with a `begin/rescue` and any exceptions within will be reported to Rollbar. We first try to send the notification synchronously since, with our app failing to boot, it is likely the async handler relies on the app booting, and will not process the notification.
1029
-
1030
- ## Rails runner command
1031
-
1032
- We aren't able to instrument `rails runner` directly, but we do provide a wrapper, `rollbar-rails-runner`, which you can use to capture errors when running commands in a `rails runner`-like way. For example:
1033
-
1034
- ```shell
1035
- $ bundle exec rollbar-rails-runner 'puts User.count'
1036
- 45
1037
- ```
1038
-
1039
- If an error occurs during that command, the exception will be reported to Rollbar.
1040
-
1041
- ## Deploy Tracking with Capistrano
1042
-
1043
- ### Capistrano 3
1044
-
1045
- Add to your `Capfile`:
1046
-
1047
- ```ruby
1048
- require 'rollbar/capistrano3'
1049
- ```
1050
-
1051
- And then, to your `deploy.rb`:
1052
-
1053
- ```ruby
1054
- set :rollbar_token, 'POST_SERVER_ITEM_ACCESS_TOKEN'
1055
- set :rollbar_env, Proc.new { fetch :stage }
1056
- set :rollbar_role, Proc.new { :app }
1057
- ```
1058
-
1059
- If you want to upload sourcemaps to Rollbar on each deployment, then you also need to specify `rollbar_sourcemaps_minified_url_base`, where `rollbar_sourcemaps_minified_url_base` is your asset host.
1060
-
1061
- ```ruby
1062
- set :rollbar_sourcemaps_minified_url_base, "https://www.my-site.com"
1063
- ```
1064
-
1065
- NOTE: We've seen problems with Capistrano version `3.0.x` where the revision reported is incorrect. Version `3.1.0` and higher works correctly.
1066
-
1067
- ### Capistrano 2
1068
-
1069
- Add the following to ```deploy.rb```:
1070
-
1071
- ```ruby
1072
- require 'rollbar/capistrano'
1073
- set :rollbar_token, 'POST_SERVER_ITEM_ACCESS_TOKEN'
1074
- ```
1075
-
1076
- Available options:
1077
-
1078
- <dl>
1079
- <dt>rollbar_token</dt>
1080
- <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.)
1081
- </dd>
1082
- <dt>rollbar_env</dt>
1083
- <dd>Deploy environment name
1084
-
1085
- Default: ```rails_env```
1086
-
1087
- </dd>
1088
- </dl>
1089
-
1090
- For ```capistrano/multistage```, try:
1091
-
1092
- ```ruby
1093
- set(:rollbar_env) { stage }
1094
- ```
1095
-
1096
- ## Counting specific gems as in-project code
1097
-
1098
- 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.
1099
-
1100
- If you want code from some specific gems to start expanded as well, you can configure this in ```config/initializers/rollbar.rb```:
1101
-
1102
- ```ruby
1103
- Rollbar.configure do |config |
1104
- config.access_token = '...'
1105
- config.project_gems = ['my_custom_gem', 'my_other_gem']
1106
- end
1107
- ```
1108
-
1109
- ## Goalie
1110
-
1111
- 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.)
1112
-
1113
-
1114
- ## Resque
1115
-
1116
- From a time ago, Resque errors reporting was supported by the gem [resque-rollbar](https://github.com/dimko/resque-rollbar). Now that functionality is built-in in the own gem. All you need to do is use `Resque::Failure::Rollbar` as the failure backend for Resque.
1117
-
1118
- In your resque configuration add next lines:
1119
-
1120
- ```ruby
1121
- require 'resque/failure/multiple'
1122
- require 'resque/failure/redis'
1123
- require 'rollbar'
1124
-
1125
- Resque::Failure::Multiple.classes = [ Resque::Failure::Redis, Resque::Failure::Rollbar ]
1126
- Resque::Failure.backend = Resque::Failure::Multiple
1127
- ```
1128
-
1129
- ## SSL
1130
-
1131
- By default we use `OpenSSL::SSL::VERIFY_PEER` for SSL very mode. Although we don't recommend change it, you can disable peer verification in case you experience SSL connection problems:
1132
-
1133
- ```ruby
1134
- Rollbar.configure do |config|
1135
- config.verify_ssl_peer = false
1136
- end
1137
- ```
1138
-
1139
- ## Web Proxies
1140
-
1141
- If your application is deployed behind a proxy server, you can set the ```https_proxy``` (note the 's') environment variable and it will be honored, including username and password, if any.
1142
-
1143
- ```shell
1144
- export https_proxy='http://some_user:some_password@some.proxy.com:80'
1145
- ```
1146
-
1147
- Alternately, you can configure the proxy settings in ```config/initializers/rollbar.rb```. If used, ```host``` is mandatory and must include the URL scheme (e.g. ```http://```), all other fields are optional:
1148
-
1149
- ```ruby
1150
- config.proxy = {
1151
- host: 'http://some.proxy.server',
1152
- port: 80,
1153
- user: 'username_if_auth_required',
1154
- password: 'password_if_auth_required'
1155
- }
1156
- ```
1157
-
1158
- ## Using with Zeus
1159
-
1160
- 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.
1161
-
1162
-
1163
- ## Configuration options
1164
-
1165
- For a listing of all configuration options available, see
1166
- [configuration](https://rollbar.com/docs/notifier/rollbar-gem/configuration).
1167
-
1168
- ## Plugins
1169
-
1170
- The support for the different frameworks and libraries is organized into different plugin definitions. The plugins architecture documentation can be found in [Plugins](https://rollbar.com/docs/notifier/rollbar-gem/plugins).
1171
-
1172
- ## Backwards Compatibility
1173
-
1174
- You can find upgrading notes in [UPGRADING.md](UPGRADING.md).
1175
-
1176
- ## Known Issues
1177
-
1178
- If you are using jRuby with Oracle and JDK7, you may be expecting some errors sending reports to our API. This is caused by a bug in that JDK and the primer number used in the SSL algorithm. In order to fix this you can set the next configuration:
1179
-
1180
- ```ruby
1181
- Rollbar.configure do|config|
1182
- config.endpoint = 'https://api-alt.rollbar.com/api/1/item/'
1183
- end
1184
- ```
1185
-
1186
- ## Supported Language/Framework Versions
1187
-
1188
- We support Ruby >= 1.8.7.
1189
-
1190
- We support Rails >= 3.0.
19
+ See our [Releases](https://github.com/rollbar/rollbar-gem/releases) page for a list of all releases, including changes.
1191
20
 
1192
21
  ## Help / Support
1193
22
 
1194
23
  If you run into any issues, please email us at [support@rollbar.com](mailto:support@rollbar.com)
1195
24
 
1196
- You can also find us in IRC: [#rollbar on chat.freenode.net](irc://chat.freenode.net/rollbar)
1197
-
1198
25
  For bug reports, please [open an issue on GitHub](https://github.com/rollbar/rollbar-gem/issues/new).
1199
26
 
1200
27
  ## Contributing
@@ -1206,3 +33,6 @@ For bug reports, please [open an issue on GitHub](https://github.com/rollbar/rol
1206
33
  5. Create new Pull Request
1207
34
 
1208
35
  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.)
36
+
37
+ ## License
38
+ Rollbar-gem is free software released under the MIT License. See [LICENSE.txt](LICENSE.txt) for details.