rollbar 1.4.3 → 1.4.4

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: 5014d11d0ce47ae5f2e50751236a81404148c787
4
- data.tar.gz: 12aa1c0e3509ebdb622083e4d90ca20b731414d5
3
+ metadata.gz: 78c1bdf59f142827061ca417def8b9e593aaa877
4
+ data.tar.gz: 760a27633c4e7460602c81c506e71028f9a29bfb
5
5
  SHA512:
6
- metadata.gz: 83428ce3fb1b1a7287a81e1f22a862b5d3c2d429e4f133c7c7e005927724f184b4123e4446e0d2a7777e23ac7856d0b769e4e9d7ffb1cf05ee29c930b25eadbc
7
- data.tar.gz: de80c650cde9ba6e3909d3b45a4b4fb6346a2b49cec49298449e2cb7201bfcf0d32b44c2dd73a3afdea35295abbead953b86015fcf03082f08fc71c6a4c8a86b
6
+ metadata.gz: 8ce84b0b7705beaa2bea77b2ff23f5ecf187ed98e52e29d0123b205e51d3591e561193b38baa1eaf0b95e16a5bc04983fb07fa91db1841913005407e9fb5108b
7
+ data.tar.gz: 8a7ce81a92a3ff906e08e6a489a29f8e99dab6cb997928b7ddc7f74f0175ffa9d4e54facb942d61ddbd10ce305b92376897689b557ae740d9a09cd0f563853b1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.4.4
4
+
5
+ New features:
6
+
7
+ - Added configuration option to gather backtraces for exceptions that don't already have one (i.e. if you do `Rollbar.error(Exception.new)`). Set `config.populate_empty_backtraces = true` to enable it. See [#206](https://github.com/rollbar/rollbar-gem/pull/206)
8
+
9
+ Bug fixes:
10
+
11
+ - Reverted capistrano change as it causes problems in some setups. See [#210](https://github.com/rollbar/rollbar-gem/pull/210)
12
+
13
+ Other:
14
+
15
+ - Refactored the Sidekiq handler (no changes to the interface). See [#197](https://github.com/rollbar/rollbar-gem/pull/197)
16
+
3
17
  ## 1.4.3
4
18
 
5
19
  New features:
data/Gemfile CHANGED
@@ -12,3 +12,9 @@ gem 'racc', :platform => :rbx
12
12
  gem 'minitest', :platform => :rbx
13
13
  gem 'rubysl-test-unit', :platform => :rbx
14
14
  gem 'rubinius-developer_tools', :platform => :rbx
15
+
16
+ if RUBY_VERSION.chars.first.to_i > 1
17
+ gem 'byebug'
18
+ else
19
+ gem 'debugger'
20
+ end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Rollbar notifier for Ruby [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=v1.4.3)](https://travis-ci.org/rollbar/rollbar-gem/branches)
1
+ # Rollbar notifier for Ruby [![Build Status](https://api.travis-ci.org/rollbar/rollbar-gem.svg?branch=v1.4.4)](https://travis-ci.org/rollbar/rollbar-gem/branches)
2
2
 
3
3
  <!-- RemoveNext -->
4
4
  Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https://rollbar.com).
@@ -9,7 +9,7 @@ Ruby gem for reporting exceptions, errors, and log messages to [Rollbar](https:/
9
9
 
10
10
  Add this line to your application's Gemfile:
11
11
 
12
- gem 'rollbar', '~> 1.4.3'
12
+ gem 'rollbar', '~> 1.4.4'
13
13
 
14
14
  And then execute:
15
15
 
@@ -379,6 +379,23 @@ Rollbar.silenced {
379
379
  }
380
380
  ```
381
381
 
382
+ # Sending backtrace without rescued exceptions
383
+
384
+ If you use the gem in this way:
385
+
386
+ ```ruby
387
+ exception = MyException.new('this is a message')
388
+ Rollbar.error(exception)
389
+ ```
390
+
391
+ 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 your exception doesn't have it. In order to enable this feature you should configure Rollbar in this way:
392
+
393
+ ```ruby
394
+ Rollbar.configure do |config|
395
+ config.populate_empty_backtraces = true
396
+ end
397
+ ```
398
+
382
399
  ## Delayed::Job integration
383
400
 
384
401
  If `delayed_job` is defined, Rollbar will automatically install a plugin that reports any uncaught exceptions that occur in jobs.
data/THANKS.md CHANGED
@@ -23,6 +23,7 @@ Huge thanks to the following contributors (by github username). For the most up-
23
23
  - [GUI](https://github.com/GUI)
24
24
  - [ixti](https://github.com/ixti)
25
25
  - [jeremyvdw](https://github.com/jeremyvdw)
26
+ - [jjb](https://github.com/jjb)
26
27
  - [johnknott](https://github.com/johnknott)
27
28
  - [jonah-williams](https://github.com/jonah-williams)
28
29
  - [jondeandres](https://github.com/jondeandres)
data/lib/rollbar.rb CHANGED
@@ -339,23 +339,20 @@ module Rollbar
339
339
  end
340
340
 
341
341
  def trace_data(exception)
342
- # parse backtrace
343
- if exception.backtrace.respond_to?( :map )
344
- frames = exception.backtrace.map { |frame|
345
- # parse the line
346
- match = frame.match(/(.*):(\d+)(?::in `([^']+)')?/)
347
- if match
348
- { :filename => match[1], :lineno => match[2].to_i, :method => match[3] }
349
- else
350
- { :filename => "<unknown>", :lineno => 0, :method => frame }
351
- end
352
- }
353
- # reverse so that the order is as rollbar expects
354
- frames.reverse!
355
- else
356
- frames = []
342
+ frames = exception_backtrace(exception).map do |frame|
343
+ # parse the line
344
+ match = frame.match(/(.*):(\d+)(?::in `([^']+)')?/)
345
+
346
+ if match
347
+ { :filename => match[1], :lineno => match[2].to_i, :method => match[3] }
348
+ else
349
+ { :filename => "<unknown>", :lineno => 0, :method => frame }
350
+ end
357
351
  end
358
352
 
353
+ # reverse so that the order is as rollbar expects
354
+ frames.reverse!
355
+
359
356
  {
360
357
  :frames => frames,
361
358
  :exception => {
@@ -365,6 +362,28 @@ module Rollbar
365
362
  }
366
363
  end
367
364
 
365
+ # Returns the backtrace to be sent to our API. There are 3 options:
366
+ #
367
+ # 1. The exception received has a backtrace, then that backtrace is returned.
368
+ # 2. configuration.populate_empty_backtraces is disabled, we return [] here
369
+ # 3. The user has configuration.populate_empty_backtraces is enabled, then:
370
+ #
371
+ # We want to send the caller as backtrace, but the first lines of that array
372
+ # are those from the user's Rollbar.error line until this method. We want
373
+ # to remove those lines.
374
+ def exception_backtrace(exception)
375
+ return exception.backtrace if exception.backtrace.respond_to?( :map )
376
+ return [] unless configuration.populate_empty_backtraces
377
+
378
+ caller_backtrace = caller
379
+ caller_backtrace.shift while caller_backtrace[0].include?(rollbar_lib_gem_dir)
380
+ caller_backtrace
381
+ end
382
+
383
+ def rollbar_lib_gem_dir
384
+ Gem::Specification.find_by_name('rollbar').gem_dir + '/lib'
385
+ end
386
+
368
387
  def trace_chain(exception)
369
388
  traces = [trace_data(exception)]
370
389
  visited = [exception]
@@ -26,6 +26,7 @@ module Rollbar
26
26
  attr_accessor :person_id_method
27
27
  attr_accessor :person_username_method
28
28
  attr_accessor :person_email_method
29
+ attr_accessor :populate_empty_backtraces
29
30
  attr_accessor :report_dj_data
30
31
  attr_accessor :request_timeout
31
32
  attr_accessor :root
@@ -67,6 +68,7 @@ module Rollbar
67
68
  @person_username_method = 'username'
68
69
  @person_email_method = 'email'
69
70
  @project_gems = []
71
+ @populate_empty_backtraces = false
70
72
  @report_dj_data = true
71
73
  @request_timeout = 3
72
74
  @scrub_fields = [:passwd, :password, :password_confirmation, :secret,
@@ -1,34 +1,33 @@
1
1
  # encoding: utf-8
2
2
 
3
- PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class]
3
+ module Rollbar
4
+ class Sidekiq
5
+ PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class]
4
6
 
5
- if Sidekiq::VERSION < '3'
6
- module Rollbar
7
- class Sidekiq
8
- def call(worker, msg, queue)
9
- yield
10
- rescue Exception => e
11
- params = msg.reject{ |k| PARAM_BLACKLIST.include?(k) }
12
- scope = { :request => { :params => params } }
7
+ def self.handle_exception(msg_or_context, e)
8
+ params = msg_or_context.reject{ |k| PARAM_BLACKLIST.include?(k) }
9
+ scope = { :request => { :params => params } }
13
10
 
14
- Rollbar.scope(scope).error(e, :use_exception_level_filters => true)
15
- raise
16
- end
11
+ Rollbar.scope(scope).error(e, :use_exception_level_filters => true)
12
+ end
13
+
14
+ def call(worker, msg, queue)
15
+ yield
16
+ rescue Exception => e
17
+ Rollbar::Sidekiq.handle_exception(msg, e)
18
+ raise
17
19
  end
18
20
  end
21
+ end
19
22
 
20
- Sidekiq.configure_server do |config|
23
+ Sidekiq.configure_server do |config|
24
+ if Sidekiq::VERSION < '3'
21
25
  config.server_middleware do |chain|
22
26
  chain.add Rollbar::Sidekiq
23
27
  end
24
- end
25
- else
26
- Sidekiq.configure_server do |config|
28
+ else
27
29
  config.error_handlers << Proc.new do |e, context|
28
- params = context.reject{ |k| PARAM_BLACKLIST.include?(k) }
29
- scope = { :request => { :params => params } }
30
-
31
- Rollbar.scope(scope).error(e, :use_exception_level_filters => true)
30
+ Rollbar::Sidekiq.handle_exception(context, e)
32
31
  end
33
32
  end
34
33
  end
@@ -34,9 +34,9 @@ end
34
34
 
35
35
  namespace :load do
36
36
  task :defaults do
37
- set :rollbar_user, fetch(:rollbar_user, Proc.new { ENV['USER'] || ENV['USERNAME'] } )
38
- set :rollbar_env, fetch(:rollbar_env, Proc.new { fetch :rails_env, 'production' } )
39
- set :rollbar_token, fetch(:rollbar_token, Proc.new { abort "Please specify the Rollbar access token, set :rollbar_token, 'your token'" } )
40
- set :rollbar_role, fetch(:rollbar_role, Proc.new { :app } )
37
+ set :rollbar_user, Proc.new { ENV['USER'] || ENV['USERNAME'] }
38
+ set :rollbar_env, Proc.new { fetch :rails_env, 'production' }
39
+ set :rollbar_token, Proc.new { abort "Please specify the Rollbar access token, set :rollbar_token, 'your token'" }
40
+ set :rollbar_role, Proc.new { :app }
41
41
  end
42
42
  end
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = "1.4.3"
2
+ VERSION = "1.4.4"
3
3
  end
data/rollbar.gemspec CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_development_dependency 'girl_friday', '>= 0.11.1'
24
24
  gem.add_development_dependency 'sucker_punch', '>= 1.0.0' if RUBY_VERSION != '1.8.7'
25
25
  gem.add_development_dependency 'sidekiq', '>= 2.13.0' if RUBY_VERSION != '1.8.7'
26
- gem.add_development_dependency 'genspec', '>= 0.2.7'
26
+ gem.add_development_dependency 'genspec', '>= 0.2.8'
27
27
  gem.add_development_dependency 'sinatra'
28
28
  gem.add_development_dependency 'resque'
29
29
  gem.add_development_dependency 'delayed_job'
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ unless RUBY_VERSION == '1.8.7'
4
+ require 'sidekiq'
5
+ require 'rollbar/sidekiq'
6
+ end
7
+
8
+ describe Rollbar::Sidekiq, :reconfigure_notifier => false do
9
+ describe '.handle_exception' do
10
+ let(:msg_or_context) { ['hello', 'error_backtrace', 'backtrace', 'goodbye'] }
11
+ let(:exception) { StandardError.new('oh noes') }
12
+ let(:rollbar) { double }
13
+ let(:expected_args) { { :request => { :params => ['hello', 'goodbye'] } } }
14
+
15
+ subject { described_class }
16
+
17
+ it 'constructs scope from filtered params' do
18
+ allow(rollbar).to receive(:error)
19
+ expect(Rollbar).to receive(:scope).with(expected_args) {rollbar}
20
+
21
+ described_class.handle_exception(msg_or_context, exception)
22
+ end
23
+
24
+ it 'sends the passed-in error to rollbar' do
25
+ allow(Rollbar).to receive(:scope).and_return(rollbar)
26
+ expect(rollbar).to receive(:error).with(exception, :use_exception_level_filters => true)
27
+
28
+ described_class.handle_exception(msg_or_context, exception)
29
+ end
30
+ end
31
+
32
+ describe '#call' do
33
+ let(:msg) { ['hello'] }
34
+ let(:exception) { StandardError.new('oh noes') }
35
+ let(:middleware_block) { proc { raise exception } }
36
+
37
+ subject { Rollbar::Sidekiq.new }
38
+
39
+ it 'sends the error to Rollbar::Sidekiq.handle_exception' do
40
+ expect(Rollbar::Sidekiq).to receive(:handle_exception).with(msg, exception)
41
+
42
+ expect { subject.call(nil, msg, nil, &middleware_block) }.to raise_error(exception)
43
+ end
44
+ end
45
+ end unless RUBY_VERSION == '1.8.7'
46
+
47
+
data/spec/rollbar_spec.rb CHANGED
@@ -879,6 +879,25 @@ describe Rollbar do
879
879
  payload["data"][:body][:trace][:exception][:message].should == "oops"
880
880
  end
881
881
 
882
+ it 'gets the backtrace from the caller' do
883
+ Rollbar.configure do |config|
884
+ config.populate_empty_backtraces = true
885
+ end
886
+
887
+ exception = Exception.new
888
+
889
+ Rollbar.error(exception)
890
+
891
+ gem_dir = Gem::Specification.find_by_name('rollbar').gem_dir
892
+ gem_lib_dir = gem_dir + '/lib'
893
+ last_report = Rollbar.last_report
894
+
895
+ filepaths = last_report[:body][:trace][:frames].map {|frame| frame[:filename] }.reverse
896
+
897
+ expect(filepaths[0]).not_to include(gem_lib_dir)
898
+ expect(filepaths.any? {|filepath| filepath.include?(gem_dir) }).to be_true
899
+ end
900
+
882
901
  it 'should return the exception data with a uuid, on platforms with SecureRandom' do
883
902
  if defined?(SecureRandom) and SecureRandom.respond_to?(:uuid)
884
903
  exception_data = Rollbar.error(StandardError.new("oops"))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 1.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-04 00:00:00.000000000 Z
11
+ date: 2015-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '>='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.2.7
117
+ version: 0.2.8
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.2.7
124
+ version: 0.2.8
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: sinatra
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -309,6 +309,7 @@ files:
309
309
  - spec/rollbar/middleware/rack/builder_spec.rb
310
310
  - spec/rollbar/middleware/sinatra_spec.rb
311
311
  - spec/rollbar/rake_spec.rb
312
+ - spec/rollbar/sidekiq_spec.rb
312
313
  - spec/rollbar/truncation/frames_strategy_spec.rb
313
314
  - spec/rollbar/truncation/min_body_strategy_spec.rb
314
315
  - spec/rollbar/truncation/strings_strategy_spec.rb
@@ -412,6 +413,7 @@ test_files:
412
413
  - spec/rollbar/middleware/rack/builder_spec.rb
413
414
  - spec/rollbar/middleware/sinatra_spec.rb
414
415
  - spec/rollbar/rake_spec.rb
416
+ - spec/rollbar/sidekiq_spec.rb
415
417
  - spec/rollbar/truncation/frames_strategy_spec.rb
416
418
  - spec/rollbar/truncation/min_body_strategy_spec.rb
417
419
  - spec/rollbar/truncation/strings_strategy_spec.rb