rollbar 2.19.1 → 2.27.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +5 -5
  2. data/.github/pull_request_template.md +25 -0
  3. data/.rubocop.yml +168 -0
  4. data/.travis.yml +63 -34
  5. data/Appraisals +10 -10
  6. data/Gemfile +35 -14
  7. data/README.md +5 -2
  8. data/Rakefile +0 -0
  9. data/data/rollbar.snippet.js +1 -1
  10. data/docs/configuration.md +17 -0
  11. data/gemfiles/rails30.gemfile +10 -10
  12. data/gemfiles/rails31.gemfile +10 -9
  13. data/gemfiles/rails32.gemfile +10 -9
  14. data/gemfiles/rails40.gemfile +10 -9
  15. data/gemfiles/rails41.gemfile +10 -9
  16. data/gemfiles/rails42.gemfile +12 -9
  17. data/gemfiles/rails50.gemfile +21 -14
  18. data/gemfiles/rails51.gemfile +21 -14
  19. data/gemfiles/rails52.gemfile +15 -12
  20. data/gemfiles/rails60.gemfile +67 -0
  21. data/lib/generators/rollbar/rollbar_generator.rb +1 -1
  22. data/lib/rails/rollbar_runner.rb +4 -2
  23. data/lib/rollbar/capistrano.rb +1 -1
  24. data/lib/rollbar/capistrano3.rb +6 -3
  25. data/lib/rollbar/capistrano_tasks.rb +29 -21
  26. data/lib/rollbar/configuration.rb +86 -16
  27. data/lib/rollbar/delay/girl_friday.rb +4 -8
  28. data/lib/rollbar/delay/resque.rb +3 -6
  29. data/lib/rollbar/delay/sidekiq.rb +4 -10
  30. data/lib/rollbar/delay/sucker_punch.rb +16 -19
  31. data/lib/rollbar/delay/thread.rb +16 -2
  32. data/lib/rollbar/deploy.rb +52 -29
  33. data/lib/rollbar/encoding/encoder.rb +17 -10
  34. data/lib/rollbar/exception_reporter.rb +19 -5
  35. data/lib/rollbar/item/backtrace.rb +13 -3
  36. data/lib/rollbar/item/frame.rb +9 -1
  37. data/lib/rollbar/item/locals.rb +100 -0
  38. data/lib/rollbar/item.rb +56 -17
  39. data/lib/rollbar/json.rb +6 -51
  40. data/lib/rollbar/language_support.rb +4 -20
  41. data/lib/rollbar/lazy_store.rb +5 -5
  42. data/lib/rollbar/logger.rb +1 -0
  43. data/lib/rollbar/logger_proxy.rb +6 -2
  44. data/lib/rollbar/middleware/js.rb +28 -18
  45. data/lib/rollbar/middleware/rack.rb +4 -1
  46. data/lib/rollbar/middleware/rails/rollbar.rb +10 -1
  47. data/lib/rollbar/notifier/trace_with_bindings.rb +65 -0
  48. data/lib/rollbar/notifier.rb +225 -89
  49. data/lib/rollbar/plugin.rb +54 -6
  50. data/lib/rollbar/plugins/active_job.rb +6 -2
  51. data/lib/rollbar/plugins/basic_socket.rb +21 -6
  52. data/lib/rollbar/plugins/delayed_job/job_data.rb +3 -3
  53. data/lib/rollbar/plugins/delayed_job/plugin.rb +13 -3
  54. data/lib/rollbar/plugins/error_context.rb +11 -0
  55. data/lib/rollbar/plugins/goalie.rb +11 -3
  56. data/lib/rollbar/plugins/rails/controller_methods.rb +15 -3
  57. data/lib/rollbar/plugins/rake.rb +2 -2
  58. data/lib/rollbar/plugins/sidekiq/plugin.rb +5 -4
  59. data/lib/rollbar/plugins.rb +7 -1
  60. data/lib/rollbar/rake_tasks.rb +4 -148
  61. data/lib/rollbar/request_data_extractor.rb +31 -21
  62. data/lib/rollbar/rollbar_test.rb +36 -0
  63. data/lib/rollbar/scrubbers/params.rb +19 -18
  64. data/lib/rollbar/scrubbers/url.rb +18 -9
  65. data/lib/rollbar/scrubbers.rb +3 -3
  66. data/lib/rollbar/truncation/frames_strategy.rb +1 -1
  67. data/lib/rollbar/truncation/min_body_strategy.rb +2 -3
  68. data/lib/rollbar/truncation/mixin.rb +1 -1
  69. data/lib/rollbar/truncation/remove_any_key_strategy.rb +123 -0
  70. data/lib/rollbar/truncation/remove_extra_strategy.rb +35 -0
  71. data/lib/rollbar/truncation/remove_request_strategy.rb +21 -0
  72. data/lib/rollbar/truncation/strings_strategy.rb +6 -5
  73. data/lib/rollbar/truncation.rb +9 -2
  74. data/lib/rollbar/util/hash.rb +15 -0
  75. data/lib/rollbar/util/ip_anonymizer.rb +8 -7
  76. data/lib/rollbar/util/ip_obfuscator.rb +1 -1
  77. data/lib/rollbar/util.rb +6 -2
  78. data/lib/rollbar/version.rb +1 -1
  79. data/lib/rollbar.rb +2 -3
  80. data/lib/tasks/benchmark.rake +103 -0
  81. data/rollbar.gemspec +13 -5
  82. data/spec/support/rollbar_api.rb +67 -0
  83. metadata +21 -23
  84. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +0 -49
  85. data/lib/rollbar/json/default.rb +0 -11
  86. data/lib/rollbar/json/oj.rb +0 -16
@@ -14,5 +14,9 @@ module Rollbar
14
14
  end
15
15
  end
16
16
 
17
- # Automatically add to ActionMailer::DeliveryJob
18
- ActionMailer::DeliveryJob.send(:include, Rollbar::ActiveJob) if defined?(ActionMailer::DeliveryJob)
17
+ if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
18
+ ActiveSupport.on_load(:action_mailer) do
19
+ # Automatically add to ActionMailer::DeliveryJob
20
+ ActionMailer::DeliveryJob.send(:include, Rollbar::ActiveJob) if defined?(ActionMailer::DeliveryJob)
21
+ end
22
+ end
@@ -1,16 +1,31 @@
1
1
  Rollbar.plugins.define('basic_socket') do
2
+ load_on_demand
3
+
2
4
  dependency { !configuration.disable_core_monkey_patch }
3
5
 
4
6
  # Needed to avoid active_support (< 4.1.0) bug serializing JSONs
5
- dependency { defined?(ActiveSupport::VERSION::STRING) }
7
+ dependency do
8
+ defined?(ActiveSupport::VERSION::STRING) &&
9
+ Gem::Version.new(ActiveSupport::VERSION::STRING) < Gem::Version.new('4.1.0')
10
+ end
6
11
 
7
12
  execute do
8
- require 'socket'
9
-
10
- class BasicSocket
11
- def as_json(*)
12
- to_s
13
+ class BasicSocket # :nodoc:
14
+ def new_as_json(_options = nil)
15
+ {
16
+ :value => inspect
17
+ }
13
18
  end
19
+ # alias_method is recommended over alias when aliasing at runtime.
20
+ # https://github.com/rubocop-hq/ruby-style-guide#alias-method
21
+ alias_method :original_as_json, :as_json # rubocop:disable Style/Alias
22
+ alias_method :as_json, :new_as_json # rubocop:disable Style/Alias
23
+ end
24
+ end
25
+
26
+ revert do
27
+ class BasicSocket # :nodoc:
28
+ alias_method :as_json, :original_as_json # rubocop:disable Style/Alias
14
29
  end
15
30
  end
16
31
  end
@@ -10,7 +10,7 @@ module Rollbar
10
10
  def to_hash
11
11
  job_data = extract_job_data
12
12
 
13
- handler_parent = job_data['job'] ? job_data['job'] : job_data
13
+ handler_parent = job_data['job'] || job_data
14
14
  handler_parent['handler'] = handler_data
15
15
 
16
16
  job_data
@@ -32,7 +32,7 @@ module Rollbar
32
32
  return payload_object unless payload_object.respond_to?(:object)
33
33
 
34
34
  object_data(payload_object.object)
35
- rescue
35
+ rescue StandardError
36
36
  {}
37
37
  end
38
38
 
@@ -42,7 +42,7 @@ module Rollbar
42
42
  :args => job.payload_object.args,
43
43
  :object => object.is_a?(Class) ? object.name : object.to_s
44
44
  }
45
- rescue
45
+ rescue StandardError
46
46
  {}
47
47
  end
48
48
  end
@@ -9,10 +9,16 @@ module Rollbar
9
9
 
10
10
  class RollbarPlugin < ::Delayed::Plugin
11
11
  callbacks do |lifecycle|
12
- lifecycle.around(:invoke_job, &Delayed::invoke_job_callback)
12
+ lifecycle.around(:invoke_job, &Delayed.invoke_job_callback)
13
13
  lifecycle.after(:failure) do |_, job, _, _|
14
14
  data = Rollbar::Delayed.build_job_data(job)
15
- ::Rollbar.scope(:request => data).error("Job has failed and won't be retried anymore: " + job.last_error, :use_exception_level_filters => true) if job.last_error
15
+
16
+ # DelayedJob < 4.1 doesn't provide job#error
17
+ if job.class.method_defined? :error
18
+ ::Rollbar.scope(:request => data).error(job.error, :use_exception_level_filters => true) if job.error
19
+ elsif job.last_error
20
+ ::Rollbar.scope(:request => data).error("Job has failed and won't be retried anymore: " + job.last_error, :use_exception_level_filters => true)
21
+ end
16
22
  end
17
23
  end
18
24
  end
@@ -37,7 +43,7 @@ module Rollbar
37
43
  proc do |job, *args, &block|
38
44
  begin
39
45
  block.call(job, *args)
40
- rescue => e
46
+ rescue StandardError => e
41
47
  report(e, job)
42
48
 
43
49
  raise e
@@ -54,6 +60,10 @@ module Rollbar
54
60
  end
55
61
 
56
62
  def self.skip_report?(job)
63
+ handler = ::Rollbar.configuration.async_skip_report_handler
64
+
65
+ return handler.call(job) if handler.respond_to?(:call)
66
+
57
67
  job.attempts < ::Rollbar.configuration.dj_threshold
58
68
  end
59
69
 
@@ -0,0 +1,11 @@
1
+ module RollbarErrorContext
2
+ attr_accessor :rollbar_context
3
+ end
4
+
5
+ Rollbar.plugins.define('error_context') do
6
+ dependency { configuration.enable_error_context }
7
+
8
+ execute! do
9
+ StandardError.send(:include, RollbarErrorContext)
10
+ end
11
+ end
@@ -10,10 +10,18 @@ Rollbar.plugins.define('goalie') do
10
10
 
11
11
  begin
12
12
  controller = env['action_controller.instance']
13
- request_data = controller.rollbar_request_data rescue nil
14
- person_data = controller.rollbar_person_data rescue nil
13
+ request_data = begin
14
+ controller.rollbar_request_data
15
+ rescue StandardError
16
+ nil
17
+ end
18
+ person_data = begin
19
+ controller.rollbar_person_data
20
+ rescue StandardError
21
+ nil
22
+ end
15
23
  exception_data = Rollbar.scope(:request => request_data, :person => person_data).error(exception, :use_exception_level_filters => true)
16
- rescue => e
24
+ rescue StandardError => e
17
25
  Rollbar.log_warning "[Rollbar] Exception while reporting exception to Rollbar: #{e}"
18
26
  end
19
27
 
@@ -11,9 +11,21 @@ module Rollbar
11
11
  # include id, username, email if non-empty
12
12
  if user
13
13
  {
14
- :id => (user.send(Rollbar.configuration.person_id_method) rescue nil),
15
- :username => (user.send(Rollbar.configuration.person_username_method) rescue nil),
16
- :email => (user.send(Rollbar.configuration.person_email_method) rescue nil)
14
+ :id => (begin
15
+ user.send(Rollbar.configuration.person_id_method)
16
+ rescue StandardError
17
+ nil
18
+ end),
19
+ :username => (begin
20
+ user.send(Rollbar.configuration.person_username_method)
21
+ rescue StandardError
22
+ nil
23
+ end),
24
+ :email => (begin
25
+ user.send(Rollbar.configuration.person_email_method)
26
+ rescue StandardError
27
+ nil
28
+ end)
17
29
  }
18
30
  else
19
31
  {}
@@ -58,9 +58,9 @@ Rollbar.plugins.define('rake') do
58
58
 
59
59
  def self.rake_version
60
60
  if Object.const_defined?('RAKEVERSION')
61
- return RAKEVERSION
61
+ RAKEVERSION
62
62
  elsif ::Rake.const_defined?('VERSION')
63
- return ::Rake::VERSION
63
+ ::Rake::VERSION
64
64
  end
65
65
  end
66
66
  end
@@ -2,10 +2,10 @@ require 'rollbar/scrubbers/params'
2
2
 
3
3
  module Rollbar
4
4
  class Sidekiq
5
- PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class]
5
+ PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class].freeze
6
6
 
7
7
  class ClearScope
8
- def call(worker, msg, queue)
8
+ def call(_worker, _msg, _queue)
9
9
  Rollbar.reset_notifier!
10
10
 
11
11
  yield
@@ -38,15 +38,16 @@ module Rollbar
38
38
  Rollbar::Scrubbers::Params.call(options)
39
39
  end
40
40
 
41
- def self.skip_report?(job_hash, e)
41
+ def self.skip_report?(job_hash, _e)
42
42
  return false if job_hash.nil?
43
+
43
44
  # when rollbar middleware catches, sidekiq's retry_job processor hasn't set
44
45
  # the retry_count for the current job yet, so adding 1 gives the actual retry count
45
46
  actual_retry_count = job_hash.fetch('retry_count', -1) + 1
46
47
  job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
47
48
  end
48
49
 
49
- def call(worker, msg, queue)
50
+ def call(_worker, msg, _queue)
50
51
  Rollbar.reset_notifier!
51
52
 
52
53
  yield
@@ -29,7 +29,13 @@ module Rollbar
29
29
  end
30
30
 
31
31
  def load!
32
- collection.each(&:load!)
32
+ collection.each do |plugin|
33
+ plugin.load! unless plugin.on_demand
34
+ end
35
+ end
36
+
37
+ def get(name)
38
+ collection.find { |plugin| plugin.name == name }
33
39
  end
34
40
 
35
41
  private
@@ -1,154 +1,10 @@
1
- require 'rollbar'
2
- begin
3
- require 'rack/mock'
4
- rescue LoadError
5
- puts 'Cannot load rack/mock'
6
- end
7
- require 'logger'
8
1
 
9
2
  namespace :rollbar do
10
- desc 'Verify your gem installation by sending a test exception to Rollbar'
3
+ desc 'Verify your gem installation by sending a test message to Rollbar'
11
4
  task :test => [:environment] do
12
- RollbarTest.run
13
- end
14
- end
15
-
16
- # Module to inject into the Rails controllers or rack apps
17
- module RollbarTest # :nodoc:
18
- def test_rollbar
19
- puts 'Raising RollbarTestingException to simulate app failure.'
20
-
21
- raise RollbarTestingException.new, ::RollbarTest.success_message
22
- end
23
-
24
- def self.run
25
- return unless confirmed_token?
26
-
27
- configure_rails if defined?(Rails)
28
-
29
- puts 'Testing manual report...'
30
- Rollbar.error('Test error from rollbar:test')
31
-
32
- return unless defined?(Rack::MockRequest)
33
-
34
- protocol, app = setup_app
35
-
36
- puts 'Processing...'
37
- env = Rack::MockRequest.env_for("#{protocol}://www.example.com/verify", 'REMOTE_ADDR' => '127.0.0.1')
38
- status, = app.call(env)
39
-
40
- puts error_message unless status.to_i == 500
41
- end
42
-
43
- def self.configure_rails
44
- Rails.logger = if defined?(ActiveSupport::TaggedLogging)
45
- ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
46
- else
47
- Logger.new(STDOUT)
48
- end
49
-
50
- Rails.logger.level = Logger::DEBUG
51
- Rollbar.preconfigure do |config|
52
- config.logger = Rails.logger
53
- end
54
- end
55
-
56
- def self.confirmed_token?
57
- return true if Rollbar.configuration.access_token
58
-
59
- puts token_error_message
60
-
61
- false
62
- end
63
-
64
- def self.authlogic_config
65
- # from http://stackoverflow.com/questions/5270835/authlogic-activation-problems
66
- return unless defined?(Authlogic)
67
-
68
- Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
69
- end
70
-
71
- def self.setup_app
72
- puts 'Setting up the test app.'
5
+ rollbar_dir = Gem.loaded_specs['rollbar'].full_gem_path
6
+ require "#{rollbar_dir}/lib/rollbar/rollbar_test"
73
7
 
74
- if defined?(Rails)
75
- app = rails_app
76
-
77
- draw_rails_route(app)
78
-
79
- authlogic_config
80
-
81
- [rails_protocol(app), app]
82
- else
83
- ['http', rack_app]
84
- end
85
- end
86
-
87
- def self.rails_app
88
- # The setup below is needed for Rails 5.x, but not for Rails 4.x and below.
89
- # (And fails on Rails 4.x in various ways depending on the exact version.)
90
- return Rails.application if Rails.version < '5.0.0'
91
-
92
- # Spring now runs by default in development on all new Rails installs. This causes
93
- # the new `/verify` route to not get picked up if `config.cache_classes == false`
94
- # which is also a default in development env.
95
- #
96
- # `config.cache_classes` needs to be set, but the only possible time is at app load,
97
- # so here we clone the default app with an updated config.
98
- #
99
- config = Rails.application.config
100
- config.cache_classes = true
101
-
102
- # Make a copy of the app, so the config can be updated.
103
- Rails.application.class.name.constantize.new(:config => config)
104
- end
105
-
106
- def self.draw_rails_route(app)
107
- app.routes_reloader.execute_if_updated
108
- app.routes.draw do
109
- get 'verify' => 'rollbar_test#verify', :as => 'verify'
110
- end
111
- end
112
-
113
- def self.rails_protocol(app)
114
- defined?(app.config.force_ssl && app.config.force_ssl) ? 'https' : 'http'
115
- end
116
-
117
- def self.rack_app
118
- Class.new do
119
- include RollbarTest
120
-
121
- def self.call(_env)
122
- new.test_rollbar
123
- end
124
- end
125
- end
126
-
127
- def self.token_error_message
128
- 'Rollbar needs an access token configured. Check the README for instructions.'
129
- end
130
-
131
- def self.error_message
132
- 'Test failed! You may have a configuration issue, or you could be using a gem that\'s blocking the test. Contact support@rollbar.com if you need help troubleshooting.'
133
- end
134
-
135
- def self.success_message
136
- 'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
137
- end
138
- end
139
-
140
- class RollbarTestingException < RuntimeError; end
141
-
142
- if defined?(Rails)
143
- class RollbarTestController < ActionController::Base # :nodoc:
144
- include RollbarTest
145
-
146
- def verify
147
- test_rollbar
148
- end
149
-
150
- def logger
151
- nil
152
- end
8
+ RollbarTest.run
153
9
  end
154
10
  end
@@ -10,15 +10,19 @@ require 'rollbar/json'
10
10
 
11
11
  module Rollbar
12
12
  module RequestDataExtractor
13
- ALLOWED_HEADERS_REGEX = /^HTTP_|^CONTENT_TYPE$|^CONTENT_LENGTH$/
14
- ALLOWED_BODY_PARSEABLE_METHODS = %w(POST PUT PATCH DELETE).freeze
13
+ ALLOWED_HEADERS_REGEX = /^HTTP_|^CONTENT_TYPE$|^CONTENT_LENGTH$/.freeze
14
+ ALLOWED_BODY_PARSEABLE_METHODS = %w[POST PUT PATCH DELETE].freeze
15
15
 
16
16
  def extract_person_data_from_controller(env)
17
- if env.has_key?('rollbar.person_data')
17
+ if env.key?('rollbar.person_data')
18
18
  person_data = env['rollbar.person_data'] || {}
19
19
  else
20
20
  controller = env['action_controller.instance']
21
- person_data = controller.rollbar_person_data rescue {}
21
+ person_data = begin
22
+ controller.rollbar_person_data
23
+ rescue StandardError
24
+ {}
25
+ end
22
26
  end
23
27
 
24
28
  person_data
@@ -50,9 +54,7 @@ module Rollbar
50
54
  :method => rollbar_request_method(env)
51
55
  }
52
56
 
53
- if env['action_dispatch.request_id']
54
- data[:request_id] = env['action_dispatch.request_id']
55
- end
57
+ data[:request_id] = env['action_dispatch.request_id'] if env['action_dispatch.request_id']
56
58
 
57
59
  data
58
60
  end
@@ -108,7 +110,7 @@ module Rollbar
108
110
  elsif name == 'X-Forwarded-For' && !Rollbar.configuration.collect_user_ip
109
111
  {}
110
112
  elsif name == 'X-Forwarded-For' && Rollbar.configuration.collect_user_ip && Rollbar.configuration.anonymize_user_ip
111
- ips = env[header].sub(" ", "").split(',')
113
+ ips = env[header].sub(' ', '').split(',')
112
114
  ips = ips.map { |ip| Rollbar::Util::IPAnonymizer.anonymize_ip(ip) }
113
115
  { name => ips.join(', ') }
114
116
  elsif name == 'X-Real-Ip' && !Rollbar.configuration.collect_user_ip
@@ -129,13 +131,14 @@ module Rollbar
129
131
  host = host.split(',').first.strip unless host.empty?
130
132
 
131
133
  path = env['ORIGINAL_FULLPATH'] || env['REQUEST_URI']
134
+ path ||= "#{env['SCRIPT_NAME']}#{env['PATH_INFO']}#{"?#{env['QUERY_STRING']}" unless env['QUERY_STRING'].to_s.empty?}"
132
135
  unless path.nil? || path.empty?
133
136
  path = '/' + path.to_s if path.to_s.slice(0, 1) != '/'
134
137
  end
135
138
 
136
139
  port = env['HTTP_X_FORWARDED_PORT']
137
- if port && !(!scheme.nil? && scheme.downcase == 'http' && port.to_i == 80) && \
138
- !(!scheme.nil? && scheme.downcase == 'https' && port.to_i == 443) && \
140
+ if port && !(!scheme.nil? && scheme.casecmp('http').zero? && port.to_i == 80) && \
141
+ !(!scheme.nil? && scheme.casecmp('https').zero? && port.to_i == 443) && \
139
142
  !(host.include? ':')
140
143
  host = host + ':' + port
141
144
  end
@@ -145,12 +148,13 @@ module Rollbar
145
148
 
146
149
  def rollbar_user_ip(env)
147
150
  return nil unless Rollbar.configuration.collect_user_ip
151
+
148
152
  user_ip_string = (env['action_dispatch.remote_ip'] || env['HTTP_X_REAL_IP'] || x_forwarded_for_client(env['HTTP_X_FORWARDED_FOR']) || env['REMOTE_ADDR']).to_s
149
153
 
150
154
  user_ip_string = Rollbar::Util::IPAnonymizer.anonymize_ip(user_ip_string)
151
155
 
152
156
  Rollbar::Util::IPObfuscator.obfuscate_ip(user_ip_string)
153
- rescue
157
+ rescue StandardError
154
158
  nil
155
159
  end
156
160
 
@@ -176,13 +180,13 @@ module Rollbar
176
180
 
177
181
  def rollbar_get_params(rack_req)
178
182
  rack_req.GET
179
- rescue
183
+ rescue StandardError
180
184
  {}
181
185
  end
182
186
 
183
187
  def rollbar_post_params(rack_req)
184
188
  rack_req.POST
185
- rescue
189
+ rescue StandardError
186
190
  {}
187
191
  end
188
192
 
@@ -195,18 +199,19 @@ module Rollbar
195
199
  raw_body = rack_req.body.read
196
200
  begin
197
201
  Rollbar::JSON.load(raw_body)
198
- rescue
202
+ rescue StandardError
199
203
  raw_body
200
204
  end
201
- rescue
205
+ rescue StandardError
202
206
  {}
203
207
  ensure
204
208
  rack_req.body.rewind
205
209
  end
206
210
 
207
211
  def json_request?(rack_req)
208
- !!(rack_req.env['CONTENT_TYPE'] =~ %r{application/json} ||
209
- rack_req.env['ACCEPT'] =~ /\bjson\b/)
212
+ json_regex = /\bjson\b/
213
+
214
+ !!(rack_req.env['CONTENT_TYPE'] =~ json_regex)
210
215
  end
211
216
 
212
217
  def rollbar_route_params(env)
@@ -219,7 +224,7 @@ module Rollbar
219
224
  # route params (if any)and format (if defined)
220
225
  ::Rails.application.routes.recognize_path(env['PATH_INFO'],
221
226
  environment)
222
- rescue
227
+ rescue StandardError
223
228
  {}
224
229
  end
225
230
  end
@@ -228,13 +233,13 @@ module Rollbar
228
233
  session = env.fetch('rack.session', {})
229
234
 
230
235
  session.to_hash
231
- rescue
236
+ rescue StandardError
232
237
  {}
233
238
  end
234
239
 
235
240
  def rollbar_request_cookies(rack_req)
236
241
  rack_req.cookies
237
- rescue
242
+ rescue StandardError
238
243
  {}
239
244
  end
240
245
 
@@ -243,7 +248,12 @@ module Rollbar
243
248
  end
244
249
 
245
250
  def sensitive_headers_list
246
- Rollbar.configuration.scrub_headers || []
251
+ return [] unless Rollbar.configuration.scrub_headers && Rollbar.configuration.scrub_headers.is_a?(Array)
252
+
253
+ # Normalize into the expected matching format
254
+ Rollbar.configuration.scrub_headers.map do |header|
255
+ header.split(/[-_]/).map(&:capitalize).join('-').gsub(/^Http-/, '')
256
+ end
247
257
  end
248
258
  end
249
259
  end
@@ -0,0 +1,36 @@
1
+ require 'rollbar'
2
+
3
+ module RollbarTest # :nodoc:
4
+ def self.run
5
+ return unless confirmed_token?
6
+
7
+ puts 'Test sending to Rollbar...'
8
+ result = Rollbar.info('Test message from rollbar:test')
9
+
10
+ if result == 'error'
11
+ puts error_message
12
+ else
13
+ puts success_message
14
+ end
15
+ end
16
+
17
+ def self.confirmed_token?
18
+ return true if Rollbar.configuration.access_token
19
+
20
+ puts token_error_message
21
+
22
+ false
23
+ end
24
+
25
+ def self.token_error_message
26
+ 'Rollbar needs an access token configured. Check the README for instructions.'
27
+ end
28
+
29
+ def self.error_message
30
+ 'Test failed! You may have a configuration issue, or you could be using a gem that\'s blocking the test. Contact support@rollbar.com if you need help troubleshooting.'
31
+ end
32
+
33
+ def self.success_message
34
+ 'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
35
+ end
36
+ end
@@ -9,8 +9,8 @@ module Rollbar
9
9
  # received parameters. It will not scrub anything that is in the scrub_whitelist
10
10
  # configuration array even if :scrub_all is true.
11
11
  class Params
12
- SKIPPED_CLASSES = [::Tempfile]
13
- ATTACHMENT_CLASSES = %w(ActionDispatch::Http::UploadedFile Rack::Multipart::UploadedFile).freeze
12
+ SKIPPED_CLASSES = [::Tempfile].freeze
13
+ ATTACHMENT_CLASSES = %w[ActionDispatch::Http::UploadedFile Rack::Multipart::UploadedFile].freeze
14
14
  SCRUB_ALL = :scrub_all
15
15
 
16
16
  def self.call(*args)
@@ -52,9 +52,10 @@ module Rollbar
52
52
  end
53
53
 
54
54
  def build_whitelist_regex(whitelist)
55
- fields = whitelist.find_all { |f| f.is_a?(String) || f.is_a?(Symbol) }
55
+ fields = whitelist.find_all { |f| f.is_a?(String) || f.is_a?(Symbol) || f.is_a?(Regexp) }
56
56
  return unless fields.any?
57
- Regexp.new(fields.map { |val| /\A#{Regexp.escape(val.to_s)}\z/ }.join('|'))
57
+
58
+ Regexp.new(fields.map { |val| val.is_a?(Regexp) ? val : /\A#{Regexp.escape(val.to_s)}\z/ }.join('|'))
58
59
  end
59
60
 
60
61
  def scrub(params, options)
@@ -70,19 +71,19 @@ module Rollbar
70
71
 
71
72
  params.to_hash.inject({}) do |result, (key, value)|
72
73
  encoded_key = Rollbar::Encoding.encode(key).to_s
73
- if (fields_regex === encoded_key) && !(whitelist_regex === encoded_key)
74
- result[key] = scrub_value(value)
75
- elsif value.is_a?(Hash)
76
- result[key] = scrub(value, options)
77
- elsif scrub_all && !(whitelist_regex === encoded_key)
78
- result[key] = scrub_value(value)
79
- elsif value.is_a?(Array)
80
- result[key] = scrub_array(value, options)
81
- elsif skip_value?(value)
82
- result[key] = "Skipped value of class '#{value.class.name}'"
83
- else
84
- result[key] = rollbar_filtered_param_value(value)
85
- end
74
+ result[key] = if (fields_regex === encoded_key) && !(whitelist_regex === encoded_key)
75
+ scrub_value(value)
76
+ elsif value.is_a?(Hash)
77
+ scrub(value, options)
78
+ elsif scrub_all && !(whitelist_regex === encoded_key)
79
+ scrub_value(value)
80
+ elsif value.is_a?(Array)
81
+ scrub_array(value, options)
82
+ elsif skip_value?(value)
83
+ "Skipped value of class '#{value.class.name}'"
84
+ else
85
+ rollbar_filtered_param_value(value)
86
+ end
86
87
 
87
88
  result
88
89
  end
@@ -102,7 +103,7 @@ module Rollbar
102
103
  if ATTACHMENT_CLASSES.include?(value.class.name)
103
104
  begin
104
105
  attachment_value(value)
105
- rescue
106
+ rescue StandardError
106
107
  'Uploaded file'
107
108
  end
108
109
  else