rollbar 2.19.2 → 2.19.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +27 -0
  3. data/Appraisals +10 -10
  4. data/Gemfile +2 -0
  5. data/README.md +4 -1
  6. data/Rakefile +0 -0
  7. data/data/rollbar.snippet.js +1 -1
  8. data/gemfiles/rails30.gemfile +2 -0
  9. data/gemfiles/rails31.gemfile +2 -0
  10. data/gemfiles/rails32.gemfile +2 -0
  11. data/gemfiles/rails40.gemfile +2 -0
  12. data/gemfiles/rails41.gemfile +2 -0
  13. data/gemfiles/rails42.gemfile +2 -0
  14. data/gemfiles/rails50.gemfile +2 -0
  15. data/gemfiles/rails51.gemfile +2 -0
  16. data/gemfiles/rails52.gemfile +2 -0
  17. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +2 -0
  18. data/lib/generators/rollbar/rollbar_generator.rb +1 -1
  19. data/lib/rails/rollbar_runner.rb +1 -1
  20. data/lib/rollbar.rb +2 -3
  21. data/lib/rollbar/capistrano3.rb +6 -3
  22. data/lib/rollbar/capistrano_tasks.rb +13 -15
  23. data/lib/rollbar/configuration.rb +10 -8
  24. data/lib/rollbar/delay/girl_friday.rb +2 -2
  25. data/lib/rollbar/delay/resque.rb +4 -6
  26. data/lib/rollbar/delay/sidekiq.rb +6 -10
  27. data/lib/rollbar/delay/sucker_punch.rb +17 -19
  28. data/lib/rollbar/delay/thread.rb +2 -2
  29. data/lib/rollbar/deploy.rb +47 -30
  30. data/lib/rollbar/encoding/encoder.rb +9 -9
  31. data/lib/rollbar/item.rb +7 -7
  32. data/lib/rollbar/item/backtrace.rb +4 -4
  33. data/lib/rollbar/item/frame.rb +7 -1
  34. data/lib/rollbar/item/locals.rb +56 -0
  35. data/lib/rollbar/json.rb +5 -2
  36. data/lib/rollbar/json/default.rb +1 -1
  37. data/lib/rollbar/json/oj.rb +1 -1
  38. data/lib/rollbar/language_support.rb +1 -1
  39. data/lib/rollbar/lazy_store.rb +5 -5
  40. data/lib/rollbar/logger.rb +1 -0
  41. data/lib/rollbar/logger_proxy.rb +1 -1
  42. data/lib/rollbar/middleware/js.rb +15 -15
  43. data/lib/rollbar/middleware/rack.rb +4 -1
  44. data/lib/rollbar/middleware/rails/rollbar.rb +10 -1
  45. data/lib/rollbar/notifier.rb +40 -15
  46. data/lib/rollbar/notifier/trace_with_bindings.rb +65 -0
  47. data/lib/rollbar/plugin.rb +54 -6
  48. data/lib/rollbar/plugins.rb +7 -1
  49. data/lib/rollbar/plugins/basic_socket.rb +21 -6
  50. data/lib/rollbar/plugins/delayed_job/job_data.rb +3 -3
  51. data/lib/rollbar/plugins/delayed_job/plugin.rb +2 -2
  52. data/lib/rollbar/plugins/goalie.rb +11 -3
  53. data/lib/rollbar/plugins/rails/controller_methods.rb +15 -3
  54. data/lib/rollbar/plugins/rake.rb +2 -2
  55. data/lib/rollbar/plugins/sidekiq/plugin.rb +5 -4
  56. data/lib/rollbar/rake_tasks.rb +2 -2
  57. data/lib/rollbar/request_data_extractor.rb +21 -18
  58. data/lib/rollbar/scrubbers.rb +7 -3
  59. data/lib/rollbar/scrubbers/params.rb +17 -16
  60. data/lib/rollbar/scrubbers/url.rb +8 -3
  61. data/lib/rollbar/truncation.rb +1 -1
  62. data/lib/rollbar/truncation/strings_strategy.rb +1 -1
  63. data/lib/rollbar/util/ip_anonymizer.rb +8 -7
  64. data/lib/rollbar/util/ip_obfuscator.rb +1 -1
  65. data/lib/rollbar/version.rb +1 -1
  66. data/lib/tasks/benchmark.rake +103 -0
  67. data/rollbar.gemspec +13 -4
  68. metadata +12 -5
@@ -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,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('5.2.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,7 +9,7 @@ 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
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
@@ -37,7 +37,7 @@ module Rollbar
37
37
  proc do |job, *args, &block|
38
38
  begin
39
39
  block.call(job, *args)
40
- rescue => e
40
+ rescue StandardError => e
41
41
  report(e, job)
42
42
 
43
43
  raise e
@@ -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
@@ -142,11 +142,11 @@ class RollbarTestingException < RuntimeError; end
142
142
  if defined?(Rails)
143
143
  class RollbarTestController < ActionController::Base # :nodoc:
144
144
  include RollbarTest
145
-
145
+
146
146
  def verify
147
147
  test_rollbar
148
148
  end
149
-
149
+
150
150
  def logger
151
151
  nil
152
152
  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
@@ -134,8 +136,8 @@ module Rollbar
134
136
  end
135
137
 
136
138
  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) && \
139
+ if port && !(!scheme.nil? && scheme.casecmp('http').zero? && port.to_i == 80) && \
140
+ !(!scheme.nil? && scheme.casecmp('https').zero? && port.to_i == 443) && \
139
141
  !(host.include? ':')
140
142
  host = host + ':' + port
141
143
  end
@@ -145,12 +147,13 @@ module Rollbar
145
147
 
146
148
  def rollbar_user_ip(env)
147
149
  return nil unless Rollbar.configuration.collect_user_ip
150
+
148
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
149
152
 
150
153
  user_ip_string = Rollbar::Util::IPAnonymizer.anonymize_ip(user_ip_string)
151
154
 
152
155
  Rollbar::Util::IPObfuscator.obfuscate_ip(user_ip_string)
153
- rescue
156
+ rescue StandardError
154
157
  nil
155
158
  end
156
159
 
@@ -176,13 +179,13 @@ module Rollbar
176
179
 
177
180
  def rollbar_get_params(rack_req)
178
181
  rack_req.GET
179
- rescue
182
+ rescue StandardError
180
183
  {}
181
184
  end
182
185
 
183
186
  def rollbar_post_params(rack_req)
184
187
  rack_req.POST
185
- rescue
188
+ rescue StandardError
186
189
  {}
187
190
  end
188
191
 
@@ -195,10 +198,10 @@ module Rollbar
195
198
  raw_body = rack_req.body.read
196
199
  begin
197
200
  Rollbar::JSON.load(raw_body)
198
- rescue
201
+ rescue StandardError
199
202
  raw_body
200
203
  end
201
- rescue
204
+ rescue StandardError
202
205
  {}
203
206
  ensure
204
207
  rack_req.body.rewind
@@ -219,7 +222,7 @@ module Rollbar
219
222
  # route params (if any)and format (if defined)
220
223
  ::Rails.application.routes.recognize_path(env['PATH_INFO'],
221
224
  environment)
222
- rescue
225
+ rescue StandardError
223
226
  {}
224
227
  end
225
228
  end
@@ -228,13 +231,13 @@ module Rollbar
228
231
  session = env.fetch('rack.session', {})
229
232
 
230
233
  session.to_hash
231
- rescue
234
+ rescue StandardError
232
235
  {}
233
236
  end
234
237
 
235
238
  def rollbar_request_cookies(rack_req)
236
239
  rack_req.cookies
237
- rescue
240
+ rescue StandardError
238
241
  {}
239
242
  end
240
243
 
@@ -1,17 +1,21 @@
1
1
  module Rollbar
2
2
  module Scrubbers
3
- extend self
3
+ module_function
4
4
 
5
5
  def scrub_value(value)
6
6
  if Rollbar.configuration.randomize_scrub_length
7
7
  random_filtered_value
8
8
  else
9
- '*' * (value.length rescue 8)
9
+ '*' * (begin
10
+ value.length
11
+ rescue StandardError
12
+ 8
13
+ end)
10
14
  end
11
15
  end
12
16
 
13
17
  def random_filtered_value
14
- '*' * (rand(5) + 3)
18
+ '*' * rand(3..7)
15
19
  end
16
20
  end
17
21
  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)
@@ -54,6 +54,7 @@ module Rollbar
54
54
  def build_whitelist_regex(whitelist)
55
55
  fields = whitelist.find_all { |f| f.is_a?(String) || f.is_a?(Symbol) }
56
56
  return unless fields.any?
57
+
57
58
  Regexp.new(fields.map { |val| /\A#{Regexp.escape(val.to_s)}\z/ }.join('|'))
58
59
  end
59
60
 
@@ -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
@@ -23,7 +23,7 @@ module Rollbar
23
23
  options.fetch(:randomize_scrub_length, true),
24
24
  options[:scrub_fields].include?(SCRUB_ALL),
25
25
  build_whitelist_regex(options[:whitelist] || []))
26
- rescue => e
26
+ rescue StandardError => e
27
27
  Rollbar.logger.error("[Rollbar] There was an error scrubbing the url: #{e}, options: #{options.inspect}")
28
28
  url
29
29
  end
@@ -33,6 +33,7 @@ module Rollbar
33
33
  def build_whitelist_regex(whitelist)
34
34
  fields = whitelist.find_all { |f| f.is_a?(String) || f.is_a?(Symbol) }
35
35
  return unless fields.any?
36
+
36
37
  Regexp.new(fields.map { |val| /\A#{Regexp.escape(val.to_s)}\z/ }.join('|'))
37
38
  end
38
39
 
@@ -95,12 +96,16 @@ module Rollbar
95
96
  if randomize_scrub_length
96
97
  random_filtered_value
97
98
  else
98
- '*' * (value.length rescue 8)
99
+ '*' * (begin
100
+ value.length
101
+ rescue StandardError
102
+ 8
103
+ end)
99
104
  end
100
105
  end
101
106
 
102
107
  def random_filtered_value
103
- '*' * (rand(5) + 3)
108
+ '*' * rand(3..7)
104
109
  end
105
110
  end
106
111
  end