rollbar 2.23.2 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +25 -0
  3. data/.github/workflows/ci.yml +118 -0
  4. data/.rubocop.yml +85 -34
  5. data/Gemfile +22 -22
  6. data/README.md +11 -9
  7. data/data/rollbar.snippet.js +1 -1
  8. data/docs/configuration.md +8 -0
  9. data/gemfiles/rails30.gemfile +18 -35
  10. data/gemfiles/rails31.gemfile +21 -37
  11. data/gemfiles/rails32.gemfile +14 -31
  12. data/gemfiles/rails40.gemfile +13 -32
  13. data/gemfiles/rails41.gemfile +12 -31
  14. data/gemfiles/rails42.gemfile +12 -35
  15. data/gemfiles/rails50.gemfile +17 -29
  16. data/gemfiles/rails51.gemfile +17 -29
  17. data/gemfiles/rails52.gemfile +7 -14
  18. data/gemfiles/rails60.gemfile +7 -20
  19. data/gemfiles/rails61.gemfile +54 -0
  20. data/lib/generators/rollbar/rollbar_generator.rb +18 -14
  21. data/lib/generators/rollbar/templates/{initializer.rb → initializer.erb} +0 -0
  22. data/lib/rails/rollbar_runner.rb +15 -6
  23. data/lib/rollbar/capistrano.rb +17 -9
  24. data/lib/rollbar/capistrano3.rb +8 -2
  25. data/lib/rollbar/capistrano_tasks.rb +44 -8
  26. data/lib/rollbar/configuration.rb +128 -84
  27. data/lib/rollbar/delay/shoryuken.rb +4 -3
  28. data/lib/rollbar/delay/sidekiq.rb +3 -1
  29. data/lib/rollbar/delay/sucker_punch.rb +1 -2
  30. data/lib/rollbar/delay/thread.rb +3 -2
  31. data/lib/rollbar/deploy.rb +8 -7
  32. data/lib/rollbar/encoding/encoder.rb +10 -3
  33. data/lib/rollbar/exception_reporter.rb +17 -8
  34. data/lib/rollbar/item/backtrace.rb +11 -9
  35. data/lib/rollbar/item/frame.rb +6 -5
  36. data/lib/rollbar/item/locals.rb +3 -2
  37. data/lib/rollbar/item.rb +68 -40
  38. data/lib/rollbar/json.rb +2 -1
  39. data/lib/rollbar/language_support.rb +0 -6
  40. data/lib/rollbar/lazy_store.rb +3 -7
  41. data/lib/rollbar/logger.rb +2 -0
  42. data/lib/rollbar/logger_proxy.rb +3 -1
  43. data/lib/rollbar/middleware/js.rb +64 -37
  44. data/lib/rollbar/middleware/rack/builder.rb +3 -3
  45. data/lib/rollbar/middleware/rack/test_session.rb +3 -3
  46. data/lib/rollbar/middleware/rack.rb +4 -4
  47. data/lib/rollbar/middleware/rails/rollbar.rb +9 -6
  48. data/lib/rollbar/middleware/rails/show_exceptions.rb +8 -4
  49. data/lib/rollbar/notifier/trace_with_bindings.rb +4 -2
  50. data/lib/rollbar/notifier.rb +272 -159
  51. data/lib/rollbar/plugin.rb +8 -8
  52. data/lib/rollbar/plugins/active_job.rb +11 -2
  53. data/lib/rollbar/plugins/delayed_job/plugin.rb +19 -2
  54. data/lib/rollbar/plugins/goalie.rb +27 -16
  55. data/lib/rollbar/plugins/rails/controller_methods.rb +18 -14
  56. data/lib/rollbar/plugins/rails/railtie30.rb +2 -1
  57. data/lib/rollbar/plugins/rails/railtie32.rb +2 -1
  58. data/lib/rollbar/plugins/rails/railtie_mixin.rb +2 -2
  59. data/lib/rollbar/plugins/rails.rb +5 -2
  60. data/lib/rollbar/plugins/rake.rb +2 -1
  61. data/lib/rollbar/plugins/sidekiq/plugin.rb +37 -20
  62. data/lib/rollbar/plugins/sidekiq.rb +1 -1
  63. data/lib/rollbar/plugins/thread.rb +8 -7
  64. data/lib/rollbar/plugins/validations.rb +3 -1
  65. data/lib/rollbar/rake_tasks.rb +1 -2
  66. data/lib/rollbar/request_data_extractor.rb +43 -16
  67. data/lib/rollbar/rollbar_test.rb +9 -118
  68. data/lib/rollbar/scrubbers/params.rb +13 -7
  69. data/lib/rollbar/scrubbers/url.rb +56 -17
  70. data/lib/rollbar/scrubbers.rb +1 -1
  71. data/lib/rollbar/truncation/remove_any_key_strategy.rb +4 -1
  72. data/lib/rollbar/truncation/remove_extra_strategy.rb +3 -1
  73. data/lib/rollbar/util/hash.rb +14 -7
  74. data/lib/rollbar/util/ip_anonymizer.rb +1 -1
  75. data/lib/rollbar/util.rb +19 -13
  76. data/lib/rollbar/version.rb +1 -1
  77. data/lib/rollbar.rb +12 -7
  78. data/lib/tasks/benchmark.rake +2 -1
  79. data/rollbar.gemspec +5 -2
  80. data/spec/support/rollbar_api.rb +67 -0
  81. metadata +9 -6
  82. data/.travis.yml +0 -284
@@ -4,12 +4,8 @@ module Rollbar
4
4
  # On Rollbar initialization, all plugins will be saved in memory and those that
5
5
  # satisfy the dependencies will be loaded
6
6
  class Plugin
7
- attr_reader :name
8
- attr_reader :dependencies
9
- attr_reader :callables
10
- attr_reader :revert_callables
11
- attr_accessor :on_demand
12
- attr_accessor :loaded
7
+ attr_reader :name, :dependencies, :callables, :revert_callables
8
+ attr_accessor :on_demand, :loaded
13
9
 
14
10
  private :loaded=
15
11
 
@@ -116,11 +112,15 @@ module Rollbar
116
112
  end
117
113
 
118
114
  def log_loading_error(error)
119
- Rollbar.log_error("Error trying to load plugin '#{name}': #{error.class}, #{error.message}")
115
+ Rollbar.log_error(
116
+ "Error trying to load plugin '#{name}': #{error.class}, #{error.message}"
117
+ )
120
118
  end
121
119
 
122
120
  def log_unloading_error(error)
123
- Rollbar.log_error("Error trying to unload plugin '#{name}': #{error.class}, #{error.message}")
121
+ Rollbar.log_error(
122
+ "Error trying to unload plugin '#{name}': #{error.class}, #{error.message}"
123
+ )
124
124
  end
125
125
  end
126
126
  end
@@ -3,11 +3,17 @@ module Rollbar
3
3
  module ActiveJob
4
4
  def self.included(base)
5
5
  base.send :rescue_from, Exception do |exception|
6
+ args = if self.class.respond_to?(:log_arguments?) && !self.class.log_arguments?
7
+ arguments.map(&Rollbar::Scrubbers.method(:scrub_value))
8
+ else
9
+ arguments
10
+ end
11
+
6
12
  Rollbar.error(exception,
7
13
  :job => self.class.name,
8
14
  :job_id => job_id,
9
15
  :use_exception_level_filters => true,
10
- :arguments => arguments)
16
+ :arguments => args)
11
17
  raise exception
12
18
  end
13
19
  end
@@ -17,6 +23,9 @@ end
17
23
  if defined?(ActiveSupport) && ActiveSupport.respond_to?(:on_load)
18
24
  ActiveSupport.on_load(:action_mailer) do
19
25
  # Automatically add to ActionMailer::DeliveryJob
20
- ActionMailer::DeliveryJob.send(:include, Rollbar::ActiveJob) if defined?(ActionMailer::DeliveryJob)
26
+ if defined?(ActionMailer::DeliveryJob)
27
+ ActionMailer::DeliveryJob.send(:include,
28
+ Rollbar::ActiveJob)
29
+ end
21
30
  end
22
31
  end
@@ -12,7 +12,19 @@ module Rollbar
12
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
+ if job.error
19
+ ::Rollbar.scope(:request => data)
20
+ .error(job.error, :use_exception_level_filters => true)
21
+ end
22
+ elsif job.last_error
23
+ ::Rollbar.scope(:request => data).error(
24
+ "Job has failed and won't be retried anymore: #{job.last_error}",
25
+ :use_exception_level_filters => true
26
+ )
27
+ end
16
28
  end
17
29
  end
18
30
  end
@@ -50,10 +62,15 @@ module Rollbar
50
62
 
51
63
  data = build_job_data(job)
52
64
 
53
- ::Rollbar.scope(:request => data).error(e, :use_exception_level_filters => true)
65
+ ::Rollbar.scope(:request => data)
66
+ .error(e, :use_exception_level_filters => true)
54
67
  end
55
68
 
56
69
  def self.skip_report?(job)
70
+ handler = ::Rollbar.configuration.async_skip_report_handler
71
+
72
+ return handler.call(job) if handler.respond_to?(:call)
73
+
57
74
  job.attempts < ::Rollbar.configuration.dj_threshold
58
75
  end
59
76
 
@@ -11,29 +11,40 @@ Rollbar.plugins.define('goalie') do
11
11
  begin
12
12
  controller = env['action_controller.instance']
13
13
  request_data = begin
14
- controller.rollbar_request_data
15
- rescue StandardError
16
- nil
17
- end
14
+ controller.rollbar_request_data
15
+ rescue StandardError
16
+ nil
17
+ end
18
18
  person_data = begin
19
- controller.rollbar_person_data
20
- rescue StandardError
21
- nil
22
- end
23
- exception_data = Rollbar.scope(:request => request_data, :person => person_data).error(exception, :use_exception_level_filters => true)
19
+ controller.rollbar_person_data
20
+ rescue StandardError
21
+ nil
22
+ end
23
+ exception_data = Rollbar.scope(
24
+ :request => request_data,
25
+ :person => person_data
26
+ ).error(exception, :use_exception_level_filters => true)
24
27
  rescue StandardError => e
25
- Rollbar.log_warning "[Rollbar] Exception while reporting exception to Rollbar: #{e}"
28
+ message = "[Rollbar] Exception while reporting exception to Rollbar: #{e}"
29
+ Rollbar.log_warning(message)
26
30
  end
27
31
 
28
32
  # if an exception was reported, save uuid in the env
29
33
  # so it can be displayed to the user on the error page
30
- if exception_data.is_a?(Hash)
34
+ case exception_data
35
+ when Hash
31
36
  env['rollbar.exception_uuid'] = exception_data[:uuid]
32
- Rollbar.log_info "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
33
- elsif exception_data == 'disabled'
34
- Rollbar.log_info '[Rollbar] Exception not reported because Rollbar is disabled'
35
- elsif exception_data == 'ignored'
36
- Rollbar.log_info '[Rollbar] Exception not reported because it was ignored'
37
+ Rollbar.log_info(
38
+ "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
39
+ )
40
+ when 'disabled'
41
+ Rollbar.log_info(
42
+ '[Rollbar] Exception not reported because Rollbar is disabled'
43
+ )
44
+ when 'ignored'
45
+ Rollbar.log_info(
46
+ '[Rollbar] Exception not reported because it was ignored'
47
+ )
37
48
  end
38
49
 
39
50
  # now continue as normal
@@ -7,30 +7,34 @@ module Rollbar
7
7
  include RequestDataExtractor
8
8
 
9
9
  def rollbar_person_data
10
- (user = send(Rollbar.configuration.person_method)) unless Rollbar::Util.method_in_stack_twice(:rollbar_person_data, __FILE__)
10
+ user = nil
11
+ unless Rollbar::Util.method_in_stack_twice(:rollbar_person_data, __FILE__)
12
+ user = send(Rollbar.configuration.person_method)
13
+ end
14
+
11
15
  # include id, username, email if non-empty
12
16
  if user
13
17
  {
14
18
  :id => (begin
15
- user.send(Rollbar.configuration.person_id_method)
16
- rescue StandardError
17
- nil
18
- end),
19
+ user.send(Rollbar.configuration.person_id_method)
20
+ rescue StandardError
21
+ nil
22
+ end),
19
23
  :username => (begin
20
- user.send(Rollbar.configuration.person_username_method)
21
- rescue StandardError
22
- nil
23
- end),
24
+ user.send(Rollbar.configuration.person_username_method)
25
+ rescue StandardError
26
+ nil
27
+ end),
24
28
  :email => (begin
25
- user.send(Rollbar.configuration.person_email_method)
26
- rescue StandardError
27
- nil
28
- end)
29
+ user.send(Rollbar.configuration.person_email_method)
30
+ rescue StandardError
31
+ nil
32
+ end)
29
33
  }
30
34
  else
31
35
  {}
32
36
  end
33
- rescue NoMethodError, NameError
37
+ rescue NameError
34
38
  {}
35
39
  end
36
40
 
@@ -11,7 +11,8 @@ module Rollbar
11
11
 
12
12
  app.config.middleware.insert_after ActionDispatch::ShowExceptions,
13
13
  Rollbar::Middleware::Rails::RollbarMiddleware
14
- ActionDispatch::ShowExceptions.send(:include, Rollbar::Middleware::Rails::ShowExceptions)
14
+ ActionDispatch::ShowExceptions.send(:include,
15
+ Rollbar::Middleware::Rails::ShowExceptions)
15
16
  end
16
17
  end
17
18
  end
@@ -11,7 +11,8 @@ module Rollbar
11
11
 
12
12
  app.config.middleware.insert_after ActionDispatch::DebugExceptions,
13
13
  Rollbar::Middleware::Rails::RollbarMiddleware
14
- ActionDispatch::DebugExceptions.send(:include, Rollbar::Middleware::Rails::ShowExceptions)
14
+ ActionDispatch::DebugExceptions.send(:include,
15
+ Rollbar::Middleware::Rails::ShowExceptions)
15
16
  end
16
17
  end
17
18
  end
@@ -16,9 +16,9 @@ module Rollbar
16
16
  config.framework = "Rails: #{::Rails::VERSION::STRING}"
17
17
  config.filepath ||= begin
18
18
  if ::Rails.application.class.respond_to?(:module_parent_name)
19
- ::Rails.application.class.module_parent_name + '.rollbar'
19
+ "#{::Rails.application.class.module_parent_name}.rollbar"
20
20
  else
21
- ::Rails.application.class.parent_name + '.rollbar'
21
+ "#{::Rails.application.class.parent_name}.rollbar"
22
22
  end
23
23
  end
24
24
  end
@@ -39,7 +39,8 @@ Rollbar.plugins.define('rails-rollbar.js') do
39
39
  end
40
40
 
41
41
  def after_secure_headers(&block)
42
- Rollbar::Railtie.initializer('rollbar.js.frameworks.rails', :after => 'secure_headers.middleware', &block)
42
+ Rollbar::Railtie.initializer('rollbar.js.frameworks.rails',
43
+ :after => 'secure_headers.middleware', &block)
43
44
  end
44
45
 
45
46
  def plugin_execute_proc_body(plugin)
@@ -52,7 +53,8 @@ Rollbar.plugins.define('rails-rollbar.js') do
52
53
  :options => Rollbar.configuration.js_options,
53
54
  :enabled => Rollbar.configuration.js_enabled
54
55
  }
55
- ::Rails.configuration.middleware.use(::Rollbar::Middleware::Js, config)
56
+ ::Rails.configuration.middleware.use(::Rollbar::Middleware::Js,
57
+ config)
56
58
  end
57
59
  end
58
60
  end
@@ -62,6 +64,7 @@ Rollbar.plugins.define('rails-rollbar.js') do
62
64
  begin
63
65
  require 'secure_headers'
64
66
  rescue LoadError
67
+ # Skip loading
65
68
  end
66
69
 
67
70
  defined?(::SecureHeaders::Middleware)
@@ -40,7 +40,8 @@ Rollbar.plugins.define('rake') do
40
40
  end
41
41
 
42
42
  def self.skip_patch
43
- warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake version is under 0.9.x. Please upgrade to 0.9.x or higher.')
43
+ warn('[Rollbar] Rollbar is disabled for Rake tasks since your Rake ' \
44
+ 'version is under 0.9.x. Please upgrade to 0.9.x or higher.')
44
45
  end
45
46
 
46
47
  def self.patch?
@@ -4,21 +4,39 @@ module Rollbar
4
4
  class Sidekiq
5
5
  PARAM_BLACKLIST = %w[backtrace error_backtrace error_message error_class].freeze
6
6
 
7
- class ClearScope
8
- def call(_worker, _msg, _queue)
9
- Rollbar.reset_notifier!
7
+ class ResetScope
8
+ def call(_worker, msg, _queue, &block)
9
+ Rollbar.reset_notifier! # clears scope
10
10
 
11
- yield
11
+ return yield unless Rollbar.configuration.sidekiq_use_scoped_block
12
+
13
+ Rollbar.scoped(Rollbar::Sidekiq.job_scope(msg), &block)
12
14
  end
13
15
  end
14
16
 
15
- def self.handle_exception(ctx_hash, e)
16
- job_hash = ctx_hash && (ctx_hash[:job] || ctx_hash)
17
- return if skip_report?(job_hash, e)
17
+ def self.handle_exception(msg, e)
18
+ return if skip_report?(msg, e)
19
+
20
+ Rollbar.scope(job_scope(msg)).error(e, :use_exception_level_filters => true)
21
+ end
22
+
23
+ def self.skip_report?(msg, _e)
24
+ job_hash = job_hash_from_msg(msg)
25
+
26
+ return false if job_hash.nil?
27
+
28
+ # when rollbar middleware catches, sidekiq's retry_job processor hasn't set
29
+ # the retry_count for the current job yet, so adding 1 gives the actual retry count
30
+ actual_retry_count = job_hash.fetch('retry_count', -1) + 1
31
+ job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
32
+ end
18
33
 
34
+ def self.job_scope(msg)
19
35
  scope = {
20
36
  :framework => "Sidekiq: #{::Sidekiq::VERSION}"
21
37
  }
38
+ job_hash = job_hash_from_msg(msg)
39
+
22
40
  unless job_hash.nil?
23
41
  params = job_hash.reject { |k| PARAM_BLACKLIST.include?(k) }
24
42
  scope[:request] = { :params => scrub_params(params) }
@@ -26,7 +44,7 @@ module Rollbar
26
44
  scope[:queue] = params['queue']
27
45
  end
28
46
 
29
- Rollbar.scope(scope).error(e, :use_exception_level_filters => true)
47
+ scope
30
48
  end
31
49
 
32
50
  def self.scrub_params(params)
@@ -38,22 +56,21 @@ module Rollbar
38
56
  Rollbar::Scrubbers::Params.call(options)
39
57
  end
40
58
 
41
- def self.skip_report?(job_hash, _e)
42
- return false if job_hash.nil?
59
+ # see https://github.com/mperham/sidekiq/wiki/Middleware#server-middleware
60
+ def call(_worker, msg, _queue, &block)
61
+ Rollbar.reset_notifier! # clears scope
43
62
 
44
- # when rollbar middleware catches, sidekiq's retry_job processor hasn't set
45
- # the retry_count for the current job yet, so adding 1 gives the actual retry count
46
- actual_retry_count = job_hash.fetch('retry_count', -1) + 1
47
- job_hash['retry'] && actual_retry_count < ::Rollbar.configuration.sidekiq_threshold
48
- end
49
-
50
- def call(_worker, msg, _queue)
51
- Rollbar.reset_notifier!
63
+ return yield unless Rollbar.configuration.sidekiq_use_scoped_block
52
64
 
53
- yield
54
- rescue Exception => e
65
+ Rollbar.scoped(Rollbar::Sidekiq.job_scope(msg), &block)
66
+ rescue Exception => e # rubocop:disable Lint/RescueException
55
67
  Rollbar::Sidekiq.handle_exception(msg, e)
56
68
  raise
57
69
  end
70
+
71
+ def self.job_hash_from_msg(msg)
72
+ msg && (msg[:job] || msg)
73
+ end
74
+ private_class_method :job_hash_from_msg
58
75
  end
59
76
  end
@@ -9,7 +9,7 @@ Rollbar.plugins.define('sidekiq >= 3') do
9
9
 
10
10
  Sidekiq.configure_server do |config|
11
11
  config.server_middleware do |chain|
12
- chain.add Rollbar::Sidekiq::ClearScope
12
+ chain.add Rollbar::Sidekiq::ResetScope
13
13
  end
14
14
 
15
15
  config.error_handlers << proc do |e, context|
@@ -1,13 +1,14 @@
1
1
  Rollbar.plugins.define('thread') do
2
- execute do
3
- Thread.class_eval do
4
- def initialize_with_rollbar(*args, &block)
2
+ module Rollbar
3
+ module ThreadPlugin
4
+ def initialize(*args)
5
5
  self[:_rollbar_notifier] ||= Rollbar.notifier.scope
6
- initialize_without_rollbar(*args, &block)
6
+ super
7
7
  end
8
-
9
- alias_method :initialize_without_rollbar, :initialize
10
- alias_method :initialize, :initialize_with_rollbar
11
8
  end
12
9
  end
10
+
11
+ execute do
12
+ Thread.send(:prepend, Rollbar::ThreadPlugin)
13
+ end
13
14
  end
@@ -17,7 +17,9 @@ Rollbar.plugins.define('active_model') do
17
17
  module ActiveRecordExtension
18
18
  def report_validation_errors_to_rollbar
19
19
  errors.full_messages.each do |error|
20
- Rollbar.log_info "[Rollbar] Reporting form validation error: #{error} for #{self}"
20
+ Rollbar.log_info(
21
+ "[Rollbar] Reporting form validation error: #{error} for #{self}"
22
+ )
21
23
  Rollbar.warning("Form Validation Error: #{error} for #{self}")
22
24
  end
23
25
  end
@@ -1,6 +1,5 @@
1
-
2
1
  namespace :rollbar do
3
- desc 'Verify your gem installation by sending a test exception to Rollbar'
2
+ desc 'Verify your gem installation by sending a test message to Rollbar'
4
3
  task :test => [:environment] do
5
4
  rollbar_dir = Gem.loaded_specs['rollbar'].full_gem_path
6
5
  require "#{rollbar_dir}/lib/rollbar/rollbar_test"
@@ -19,10 +19,10 @@ module Rollbar
19
19
  else
20
20
  controller = env['action_controller.instance']
21
21
  person_data = begin
22
- controller.rollbar_person_data
23
- rescue StandardError
24
- {}
25
- end
22
+ controller.rollbar_person_data
23
+ rescue StandardError
24
+ {}
25
+ end
26
26
  end
27
27
 
28
28
  person_data
@@ -34,7 +34,8 @@ module Rollbar
34
34
 
35
35
  get_params = scrub_params(rollbar_get_params(rack_req), sensitive_params)
36
36
  post_params = scrub_params(rollbar_post_params(rack_req), sensitive_params)
37
- raw_body_params = scrub_params(mergeable_raw_body_params(rack_req), sensitive_params)
37
+ raw_body_params = scrub_params(mergeable_raw_body_params(rack_req),
38
+ sensitive_params)
38
39
  cookies = scrub_params(rollbar_request_cookies(rack_req), sensitive_params)
39
40
  session = scrub_params(rollbar_request_session(env), sensitive_params)
40
41
  route_params = scrub_params(rollbar_route_params(env), sensitive_params)
@@ -54,7 +55,10 @@ module Rollbar
54
55
  :method => rollbar_request_method(env)
55
56
  }
56
57
 
57
- data[:request_id] = env['action_dispatch.request_id'] if env['action_dispatch.request_id']
58
+ if env['action_dispatch.request_id']
59
+ data[:request_id] =
60
+ env['action_dispatch.request_id']
61
+ end
58
62
 
59
63
  data
60
64
  end
@@ -87,9 +91,10 @@ module Rollbar
87
91
  def mergeable_raw_body_params(rack_req)
88
92
  raw_body_params = rollbar_raw_body_params(rack_req)
89
93
 
90
- if raw_body_params.is_a?(Hash)
94
+ case raw_body_params
95
+ when Hash
91
96
  raw_body_params
92
- elsif raw_body_params.is_a?(Array)
97
+ when Array
93
98
  { 'body.multi' => raw_body_params }
94
99
  else
95
100
  { 'body.value' => raw_body_params }
@@ -109,13 +114,17 @@ module Rollbar
109
114
  { name => Rollbar::Scrubbers.scrub_value(env[header]) }
110
115
  elsif name == 'X-Forwarded-For' && !Rollbar.configuration.collect_user_ip
111
116
  {}
112
- elsif name == 'X-Forwarded-For' && Rollbar.configuration.collect_user_ip && Rollbar.configuration.anonymize_user_ip
117
+ elsif name == 'X-Forwarded-For' &&
118
+ Rollbar.configuration.collect_user_ip &&
119
+ Rollbar.configuration.anonymize_user_ip
113
120
  ips = env[header].sub(' ', '').split(',')
114
121
  ips = ips.map { |ip| Rollbar::Util::IPAnonymizer.anonymize_ip(ip) }
115
122
  { name => ips.join(', ') }
116
123
  elsif name == 'X-Real-Ip' && !Rollbar.configuration.collect_user_ip
117
124
  {}
118
- elsif name == 'X-Real-Ip' && Rollbar.configuration.collect_user_ip && Rollbar.configuration.anonymize_user_ip
125
+ elsif name == 'X-Real-Ip' &&
126
+ Rollbar.configuration.collect_user_ip &&
127
+ Rollbar.configuration.anonymize_user_ip
119
128
  { name => Rollbar::Util::IPAnonymizer.anonymize_ip(env[header]) }
120
129
  else
121
130
  { name => env[header] }
@@ -131,15 +140,15 @@ module Rollbar
131
140
  host = host.split(',').first.strip unless host.empty?
132
141
 
133
142
  path = env['ORIGINAL_FULLPATH'] || env['REQUEST_URI']
134
- unless path.nil? || path.empty?
135
- path = '/' + path.to_s if path.to_s.slice(0, 1) != '/'
136
- end
143
+ query = env['QUERY_STRING'].to_s.empty? ? nil : "?#{env['QUERY_STRING']}"
144
+ path ||= "#{env['SCRIPT_NAME']}#{env['PATH_INFO']}#{query}"
145
+ path = "/#{path}" if !(path.nil? || path.empty?) && (path.to_s.slice(0, 1) != '/')
137
146
 
138
147
  port = env['HTTP_X_FORWARDED_PORT']
139
148
  if port && !(!scheme.nil? && scheme.casecmp('http').zero? && port.to_i == 80) && \
140
149
  !(!scheme.nil? && scheme.casecmp('https').zero? && port.to_i == 443) && \
141
150
  !(host.include? ':')
142
- host = host + ':' + port
151
+ host = "#{host}:#{port}"
143
152
  end
144
153
 
145
154
  [scheme, '://', host, path].join
@@ -148,7 +157,11 @@ module Rollbar
148
157
  def rollbar_user_ip(env)
149
158
  return nil unless Rollbar.configuration.collect_user_ip
150
159
 
151
- 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
160
+ user_ip_string = (user_ip_at_configured_key(env) ||
161
+ env['action_dispatch.remote_ip'] ||
162
+ env['HTTP_X_REAL_IP'] ||
163
+ x_forwarded_for_client(env['HTTP_X_FORWARDED_FOR']) ||
164
+ env['REMOTE_ADDR']).to_s
152
165
 
153
166
  user_ip_string = Rollbar::Util::IPAnonymizer.anonymize_ip(user_ip_string)
154
167
 
@@ -157,6 +170,12 @@ module Rollbar
157
170
  nil
158
171
  end
159
172
 
173
+ def user_ip_at_configured_key(env)
174
+ return nil unless Rollbar.configuration.user_ip_rack_env_key
175
+
176
+ env[Rollbar.configuration.user_ip_rack_env_key]
177
+ end
178
+
160
179
  def x_forwarded_for_client(header_value)
161
180
  return nil unless header_value
162
181
 
@@ -247,7 +266,15 @@ module Rollbar
247
266
  end
248
267
 
249
268
  def sensitive_headers_list
250
- Rollbar.configuration.scrub_headers || []
269
+ unless Rollbar.configuration.scrub_headers &&
270
+ Rollbar.configuration.scrub_headers.is_a?(Array)
271
+ return []
272
+ end
273
+
274
+ # Normalize into the expected matching format
275
+ Rollbar.configuration.scrub_headers.map do |header|
276
+ header.split(/[-_]/).map(&:capitalize).join('-').gsub(/^Http-/, '')
277
+ end
251
278
  end
252
279
  end
253
280
  end