rollbar 2.22.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +34 -0
  3. data/.github/workflows/ci.yml +104 -0
  4. data/.rubocop.yml +185 -33
  5. data/Gemfile +26 -28
  6. data/README.md +32 -8
  7. data/data/rollbar.snippet.js +1 -1
  8. data/docs/configuration.md +8 -0
  9. data/gemfiles/rails30.gemfile +17 -35
  10. data/gemfiles/rails31.gemfile +20 -37
  11. data/gemfiles/rails32.gemfile +13 -31
  12. data/gemfiles/rails40.gemfile +12 -32
  13. data/gemfiles/rails41.gemfile +11 -31
  14. data/gemfiles/rails42.gemfile +12 -32
  15. data/gemfiles/rails50.gemfile +16 -30
  16. data/gemfiles/rails51.gemfile +16 -30
  17. data/gemfiles/rails52.gemfile +10 -19
  18. data/gemfiles/rails60.gemfile +10 -25
  19. data/gemfiles/rails61.gemfile +52 -0
  20. data/gemfiles/rails70.gemfile +52 -0
  21. data/lib/generators/rollbar/rollbar_generator.rb +18 -14
  22. data/lib/rails/rollbar_runner.rb +11 -20
  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 +138 -84
  27. data/lib/rollbar/delay/girl_friday.rb +3 -7
  28. data/lib/rollbar/delay/resque.rb +2 -3
  29. data/lib/rollbar/delay/shoryuken.rb +4 -3
  30. data/lib/rollbar/delay/sidekiq.rb +5 -5
  31. data/lib/rollbar/delay/sucker_punch.rb +4 -6
  32. data/lib/rollbar/delay/thread.rb +17 -2
  33. data/lib/rollbar/deploy.rb +8 -7
  34. data/lib/rollbar/encoding/encoder.rb +17 -6
  35. data/lib/rollbar/encoding.rb +2 -7
  36. data/lib/rollbar/exception_reporter.rb +17 -8
  37. data/lib/rollbar/item/backtrace.rb +22 -10
  38. data/lib/rollbar/item/frame.rb +8 -5
  39. data/lib/rollbar/item/locals.rb +49 -2
  40. data/lib/rollbar/item.rb +80 -50
  41. data/lib/rollbar/json.rb +2 -1
  42. data/lib/rollbar/language_support.rb +0 -6
  43. data/lib/rollbar/lazy_store.rb +3 -7
  44. data/lib/rollbar/logger.rb +2 -0
  45. data/lib/rollbar/logger_proxy.rb +3 -1
  46. data/lib/rollbar/middleware/js/json_value.rb +15 -5
  47. data/lib/rollbar/middleware/js.rb +70 -38
  48. data/lib/rollbar/middleware/rack/builder.rb +3 -3
  49. data/lib/rollbar/middleware/rack/test_session.rb +3 -3
  50. data/lib/rollbar/middleware/rack.rb +4 -4
  51. data/lib/rollbar/middleware/rails/rollbar.rb +9 -6
  52. data/lib/rollbar/middleware/rails/show_exceptions.rb +8 -4
  53. data/lib/rollbar/notifier/trace_with_bindings.rb +13 -3
  54. data/lib/rollbar/notifier.rb +309 -172
  55. data/lib/rollbar/plugin.rb +8 -8
  56. data/lib/rollbar/plugins/active_job.rb +20 -3
  57. data/lib/rollbar/plugins/delayed_job/plugin.rb +19 -2
  58. data/lib/rollbar/plugins/error_context.rb +11 -0
  59. data/lib/rollbar/plugins/goalie.rb +27 -16
  60. data/lib/rollbar/plugins/rails/controller_methods.rb +18 -14
  61. data/lib/rollbar/plugins/rails/railtie30.rb +2 -1
  62. data/lib/rollbar/plugins/rails/railtie32.rb +2 -1
  63. data/lib/rollbar/plugins/rails/railtie_mixin.rb +2 -2
  64. data/lib/rollbar/plugins/rails.rb +5 -2
  65. data/lib/rollbar/plugins/rake.rb +2 -1
  66. data/lib/rollbar/plugins/sidekiq/plugin.rb +39 -21
  67. data/lib/rollbar/plugins/sidekiq.rb +1 -1
  68. data/lib/rollbar/plugins/thread.rb +8 -7
  69. data/lib/rollbar/plugins/validations.rb +3 -1
  70. data/lib/rollbar/rake_tasks.rb +1 -2
  71. data/lib/rollbar/request_data_extractor.rb +53 -19
  72. data/lib/rollbar/rollbar_test.rb +9 -118
  73. data/lib/rollbar/scrubbers/params.rb +13 -7
  74. data/lib/rollbar/scrubbers/url.rb +56 -17
  75. data/lib/rollbar/scrubbers.rb +2 -6
  76. data/lib/rollbar/truncation/frames_strategy.rb +1 -1
  77. data/lib/rollbar/truncation/mixin.rb +1 -1
  78. data/lib/rollbar/truncation/remove_any_key_strategy.rb +4 -1
  79. data/lib/rollbar/truncation/remove_extra_strategy.rb +3 -1
  80. data/lib/rollbar/truncation/strings_strategy.rb +4 -2
  81. data/lib/rollbar/util/hash.rb +14 -7
  82. data/lib/rollbar/util/ip_anonymizer.rb +1 -1
  83. data/lib/rollbar/util.rb +23 -13
  84. data/lib/rollbar/version.rb +1 -1
  85. data/lib/rollbar.rb +12 -7
  86. data/lib/tasks/benchmark.rake +2 -1
  87. data/rollbar.gemspec +6 -3
  88. data/spec/support/rollbar_api.rb +67 -0
  89. metadata +19 -12
  90. data/.travis.yml +0 -281
  91. data/lib/rollbar/encoding/legacy_encoder.rb +0 -20
  92. /data/lib/generators/rollbar/templates/{initializer.rb → initializer.erb} +0 -0
@@ -4,71 +4,82 @@ module Rollbar
4
4
  class Configuration
5
5
  SEND_EXTRA_FRAME_DATA_OPTIONS = [:none, :app, :all].freeze
6
6
 
7
- attr_accessor :access_token
8
- attr_accessor :async_handler
9
- attr_accessor :branch
10
- attr_reader :before_process
11
- attr_accessor :capture_uncaught
12
- attr_accessor :code_version
13
- attr_accessor :custom_data_method
14
- attr_accessor :delayed_job_enabled
15
- attr_accessor :default_logger
16
- attr_reader :logger_level
17
- attr_accessor :disable_monkey_patch
18
- attr_accessor :disable_rack_monkey_patch
19
- attr_accessor :disable_core_monkey_patch
20
- attr_accessor :dj_threshold
21
- attr_accessor :enabled
22
- attr_accessor :endpoint
23
- attr_accessor :environment
24
- attr_accessor :exception_level_filters
25
- attr_accessor :failover_handlers
26
- attr_accessor :filepath
27
- attr_accessor :framework
28
- attr_accessor :ignored_person_ids
29
- attr_accessor :host
30
- attr_accessor :locals
31
- attr_writer :logger
32
- attr_accessor :payload_options
33
- attr_accessor :person_method
34
- attr_accessor :person_id_method
35
- attr_accessor :person_username_method
36
- attr_accessor :person_email_method
37
- attr_accessor :populate_empty_backtraces
38
- attr_accessor :report_dj_data
39
- attr_accessor :open_timeout
40
- attr_accessor :request_timeout
41
- attr_accessor :net_retries
42
- attr_accessor :root
43
- attr_accessor :js_options
44
- attr_accessor :js_enabled
45
- attr_accessor :safely
46
- attr_accessor :scrub_fields
47
- attr_accessor :scrub_user
48
- attr_accessor :scrub_password
49
- attr_accessor :scrub_whitelist
50
- attr_accessor :collect_user_ip
51
- attr_accessor :anonymize_user_ip
52
- attr_accessor :user_ip_obfuscator_secret
53
- attr_accessor :randomize_scrub_length
54
- attr_accessor :uncaught_exception_level
55
- attr_accessor :scrub_headers
56
- attr_accessor :sidekiq_threshold
57
- attr_reader :transform
58
- attr_accessor :verify_ssl_peer
59
- attr_accessor :use_async
60
- attr_reader :use_eventmachine
61
- attr_accessor :web_base
62
- attr_accessor :write_to_file
63
- attr_reader :send_extra_frame_data
64
- attr_accessor :use_exception_level_filters_default
65
- attr_accessor :proxy
66
- attr_accessor :raise_on_error
67
- attr_accessor :transmit
68
- attr_accessor :log_payload
69
-
70
- attr_reader :project_gem_paths
71
- attr_accessor :configured_options
7
+ attr_accessor :access_token,
8
+ :anonymize_user_ip,
9
+ :async_handler,
10
+ :async_json_payload,
11
+ :async_skip_report_handler,
12
+ :backtrace_cleaner,
13
+ :branch,
14
+ :capture_uncaught,
15
+ :code_version,
16
+ :collect_user_ip,
17
+ :configured_options,
18
+ :custom_data_method,
19
+ :default_logger,
20
+ :delayed_job_enabled,
21
+ :disable_core_monkey_patch,
22
+ :disable_monkey_patch,
23
+ :disable_rack_monkey_patch,
24
+ :dj_threshold,
25
+ :enable_error_context,
26
+ :enabled,
27
+ :endpoint,
28
+ :environment,
29
+ :exception_level_filters,
30
+ :failover_handlers,
31
+ :filepath,
32
+ :files_processed_duration,
33
+ :files_processed_enabled,
34
+ :files_processed_size,
35
+ :files_with_pid_name_enabled,
36
+ :framework,
37
+ :ignore_internal_errors,
38
+ :ignored_person_ids,
39
+ :js_enabled,
40
+ :js_options,
41
+ :host,
42
+ :locals,
43
+ :log_payload,
44
+ :net_retries,
45
+ :open_timeout,
46
+ :payload_options,
47
+ :person_email_method,
48
+ :person_id_method,
49
+ :person_method,
50
+ :person_username_method,
51
+ :populate_empty_backtraces,
52
+ :proxy,
53
+ :raise_on_error,
54
+ :randomize_scrub_length,
55
+ :report_dj_data,
56
+ :request_timeout,
57
+ :root,
58
+ :safely,
59
+ :scrub_fields,
60
+ :scrub_password,
61
+ :scrub_user,
62
+ :scrub_whitelist,
63
+ :transmit,
64
+ :uncaught_exception_level,
65
+ :user_ip_obfuscator_secret,
66
+ :user_ip_rack_env_key,
67
+ :scrub_headers,
68
+ :sidekiq_threshold,
69
+ :sidekiq_use_scoped_block,
70
+ :use_async,
71
+ :use_exception_level_filters_default,
72
+ :use_payload_access_token,
73
+ :verify_ssl_peer,
74
+ :web_base,
75
+ :write_to_file
76
+ attr_reader :before_process,
77
+ :logger_level,
78
+ :project_gem_paths,
79
+ :send_extra_frame_data,
80
+ :transform,
81
+ :use_eventmachine
82
+ attr_writer :logger # seconds # bytes
72
83
 
73
84
  alias safely? safely
74
85
 
@@ -76,18 +87,22 @@ module Rollbar
76
87
  DEFAULT_WEB_BASE = 'https://rollbar.com'.freeze
77
88
 
78
89
  def initialize
90
+ @access_token = nil
79
91
  @async_handler = nil
80
92
  @before_process = []
93
+ @branch = nil
81
94
  @capture_uncaught = nil
82
95
  @code_version = nil
83
96
  @custom_data_method = nil
84
- @default_logger = lambda { ::Logger.new(STDERR) }
97
+ @default_logger = lambda { ::Logger.new($stderr) }
85
98
  @logger_level = :info
86
99
  @delayed_job_enabled = true
87
100
  @disable_monkey_patch = false
88
101
  @disable_core_monkey_patch = false
89
102
  @disable_rack_monkey_patch = false
103
+ @enable_error_context = true
90
104
  @dj_threshold = 0
105
+ @async_skip_report_handler = nil
91
106
  @enabled = nil # set to true when configure is called
92
107
  @endpoint = DEFAULT_ENDPOINT
93
108
  @environment = nil
@@ -98,7 +113,13 @@ module Rollbar
98
113
  }
99
114
  @failover_handlers = []
100
115
  @framework = 'Plain'
116
+ @ignore_internal_errors = [
117
+ 'Net::ReadTimeout',
118
+ 'Net::OpenTimeout',
119
+ 'SocketError'
120
+ ]
101
121
  @ignored_person_ids = []
122
+ @host = nil
102
123
  @payload_options = {}
103
124
  @person_method = 'current_user'
104
125
  @person_id_method = 'id'
@@ -110,6 +131,7 @@ module Rollbar
110
131
  @open_timeout = 3
111
132
  @request_timeout = 3
112
133
  @net_retries = 3
134
+ @root = nil
113
135
  @js_enabled = false
114
136
  @js_options = {}
115
137
  @locals = {}
@@ -118,18 +140,19 @@ module Rollbar
118
140
  :api_key, :access_token, :accessToken, :session_id]
119
141
  @scrub_user = true
120
142
  @scrub_password = true
121
- @randomize_scrub_length = true
143
+ @randomize_scrub_length = false
122
144
  @scrub_whitelist = []
123
145
  @uncaught_exception_level = 'error'
124
146
  @scrub_headers = ['Authorization']
125
147
  @sidekiq_threshold = 0
148
+ @sidekiq_use_scoped_block = false
126
149
  @safely = false
127
150
  @transform = []
128
151
  @use_async = false
152
+ @async_json_payload = false
129
153
  @use_eventmachine = false
130
154
  @verify_ssl_peer = true
131
155
  @web_base = DEFAULT_WEB_BASE
132
- @write_to_file = false
133
156
  @send_extra_frame_data = :none
134
157
  @project_gem_paths = []
135
158
  @use_exception_level_filters_default = false
@@ -139,11 +162,22 @@ module Rollbar
139
162
  @log_payload = false
140
163
  @collect_user_ip = true
141
164
  @anonymize_user_ip = false
165
+ @user_ip_obfuscator_secret = nil
166
+ @user_ip_rack_env_key = nil
167
+ @backtrace_cleaner = nil
142
168
  @hooks = {
143
169
  :on_error_response => nil, # params: response
144
170
  :on_report_internal_error => nil # params: exception
145
171
  }
146
172
 
173
+ @write_to_file = false
174
+ @filepath = nil
175
+ @files_with_pid_name_enabled = false
176
+ @files_processed_enabled = false
177
+ @files_processed_duration = 60
178
+ @files_processed_size = 5 * 1000 * 1000
179
+ @use_payload_access_token = false
180
+
147
181
  @configured_options = ConfiguredOptions.new(self)
148
182
  end
149
183
 
@@ -186,7 +220,8 @@ module Rollbar
186
220
  def use_active_job(options = {})
187
221
  require 'rollbar/delay/active_job'
188
222
 
189
- Rollbar::Delay::ActiveJob.queue_as(options[:queue] || Rollbar::Delay::ActiveJob.default_queue_name)
223
+ Rollbar::Delay::ActiveJob.queue_as(options[:queue] ||
224
+ Rollbar::Delay::ActiveJob.default_queue_name)
190
225
 
191
226
  @use_async = true
192
227
  @async_handler = Rollbar::Delay::ActiveJob
@@ -226,15 +261,21 @@ module Rollbar
226
261
  end
227
262
 
228
263
  def use_sidekiq=(value)
229
- deprecation_message = '#use_sidekiq=(value) has been deprecated in favor of #use_sidekiq(options = {}). Please update your rollbar configuration.'
230
- defined?(ActiveSupport) ? ActiveSupport::Deprecation.warn(deprecation_message) : puts(deprecation_message)
264
+ deprecation_message = '#use_sidekiq=(value) has been deprecated in favor ' \
265
+ 'of #use_sidekiq(options = {}). Please update your rollbar configuration.'
266
+ if defined?(ActiveSupport)
267
+ ActiveSupport::Deprecation.warn(deprecation_message)
268
+ else
269
+ puts(deprecation_message)
270
+ end
231
271
 
232
272
  value.is_a?(Hash) ? use_sidekiq(value) : use_sidekiq
233
273
  end
234
274
 
235
- def use_thread
275
+ def use_thread(options = {})
236
276
  require 'rollbar/delay/thread'
237
277
  @use_async = true
278
+ Rollbar::Delay::Thread.options = options
238
279
  @async_handler = Rollbar::Delay::Thread
239
280
  end
240
281
 
@@ -245,8 +286,13 @@ module Rollbar
245
286
  end
246
287
 
247
288
  def use_sucker_punch=(_value)
248
- deprecation_message = '#use_sucker_punch=(value) has been deprecated in favor of #use_sucker_punch. Please update your rollbar configuration.'
249
- defined?(ActiveSupport) ? ActiveSupport::Deprecation.warn(deprecation_message) : puts(deprecation_message)
289
+ deprecation_message = '#use_sucker_punch=(value) has been deprecated in ' \
290
+ 'favor of #use_sucker_punch. Please update your rollbar configuration.'
291
+ if defined?(ActiveSupport)
292
+ ActiveSupport::Deprecation.warn(deprecation_message)
293
+ else
294
+ puts(deprecation_message)
295
+ end
250
296
 
251
297
  use_sucker_punch
252
298
  end
@@ -261,7 +307,10 @@ module Rollbar
261
307
  found = Gem::Specification.each.select { |spec| name === spec.name }
262
308
  puts "[Rollbar] No gems found matching #{name.inspect}" if found.empty?
263
309
  found
264
- end.flatten.uniq.map(&:gem_dir)
310
+ end
311
+ @project_gem_paths.flatten!
312
+ @project_gem_paths.uniq!
313
+ @project_gem_paths.map!(&:gem_dir)
265
314
  end
266
315
 
267
316
  def before_process=(*handler)
@@ -274,7 +323,9 @@ module Rollbar
274
323
 
275
324
  def send_extra_frame_data=(value)
276
325
  unless SEND_EXTRA_FRAME_DATA_OPTIONS.include?(value)
277
- logger.warning("Wrong 'send_extra_frame_data' value, :none, :app or :full is expected")
326
+ logger.warning(
327
+ "Wrong 'send_extra_frame_data' value, :none, :app or :all is expected"
328
+ )
278
329
 
279
330
  return
280
331
  end
@@ -300,14 +351,14 @@ module Rollbar
300
351
  end
301
352
 
302
353
  def hook(symbol, &block)
303
- if @hooks.key?(symbol)
304
- if block_given?
305
- @hooks[symbol] = block
306
- else
307
- @hooks[symbol]
308
- end
354
+ unless @hooks.key?(symbol)
355
+ raise StandardError, "Hook :#{symbol} is not supported by Rollbar SDK."
356
+ end
357
+
358
+ if block_given?
359
+ @hooks[symbol] = block
309
360
  else
310
- raise StandardError, 'Hook :' + symbol.to_s + ' is not supported by Rollbar SDK.'
361
+ @hooks[symbol]
311
362
  end
312
363
  end
313
364
 
@@ -328,7 +379,10 @@ module Rollbar
328
379
  return super unless configuration.respond_to?(method)
329
380
 
330
381
  method_string = method.to_s
331
- configured[method_string.chomp('=').to_sym] = args.first if method_string.end_with?('=')
382
+ if method_string.end_with?('=')
383
+ configured[method_string.chomp('=').to_sym] =
384
+ args.first
385
+ end
332
386
 
333
387
  configuration.send(method, *args, &block)
334
388
  end
@@ -12,13 +12,9 @@ module Rollbar
12
12
 
13
13
  def queue
14
14
  @queue ||= queue_class.new(nil, :size => 5) do |payload|
15
- begin
16
- Rollbar.process_from_async_handler(payload)
17
- rescue StandardError
18
- # According to https://github.com/mperham/girl_friday/wiki#error-handling
19
- # we reraise the exception so it can be handled some way
20
- raise
21
- end
15
+ Rollbar.process_from_async_handler(payload)
16
+
17
+ # Do not rescue. GirlFriday will call the error handler.
22
18
  end
23
19
  end
24
20
  end
@@ -24,9 +24,8 @@ module Rollbar
24
24
 
25
25
  def perform(payload)
26
26
  Rollbar.process_from_async_handler(payload)
27
- rescue StandardError
28
- # Raise the exception so Resque can track the errored job
29
- raise
27
+
28
+ # Do not rescue. Resque will call the error handler.
30
29
  end
31
30
  end
32
31
  end
@@ -2,9 +2,10 @@ require 'shoryuken'
2
2
 
3
3
  module Rollbar
4
4
  module Delay
5
- # Following class allows to send rollbars using Sho-ryu-ken as a background jobs processor.
6
- # see the queue_name method which states that your queues needs to be names as "rollbar_ENVIRONMENT".
7
- # retry intervals will be used to retry sending the same message again if failed before.
5
+ # Following class allows to send rollbars using Sho-ryu-ken as a background
6
+ # jobs processor. See the queue_name method which states that your queues
7
+ # needs to be names as "rollbar_ENVIRONMENT". Retry intervals will be used
8
+ # to retry sending the same message again if failed before.
8
9
  class Shoryuken
9
10
  include ::Shoryuken::Worker
10
11
 
@@ -10,17 +10,17 @@ module Rollbar
10
10
  end
11
11
 
12
12
  def call(payload)
13
- raise StandardError, 'Unable to push the job to Sidekiq' if ::Sidekiq::Client.push(@options.merge('args' => [payload])).nil?
13
+ return unless ::Sidekiq::Client.push(@options.merge('args' => [payload])).nil?
14
+
15
+ raise(StandardError, 'Unable to push the job to Sidekiq')
14
16
  end
15
17
 
16
18
  include ::Sidekiq::Worker
17
19
 
18
20
  def perform(*args)
19
21
  Rollbar.process_from_async_handler(*args)
20
- rescue StandardError
21
- # Raise the exception so Sidekiq can track the errored job
22
- # and retry it
23
- raise
22
+
23
+ # Do not rescue. Sidekiq will call the error handler.
24
24
  end
25
25
  end
26
26
  end
@@ -7,8 +7,7 @@ module Rollbar
7
7
  include ::SuckerPunch::Job
8
8
 
9
9
  class << self
10
- attr_accessor :perform_proc
11
- attr_accessor :ready
10
+ attr_accessor :perform_proc, :ready
12
11
  end
13
12
 
14
13
  self.ready = false
@@ -33,7 +32,7 @@ module Rollbar
33
32
 
34
33
  def perform(*args)
35
34
  Rollbar.process_from_async_handler(*args)
36
- rescue StandardError
35
+
37
36
  # SuckerPunch can configure an exception handler with:
38
37
  #
39
38
  # SuckerPunch.exception_handler { # do something here }
@@ -41,9 +40,8 @@ module Rollbar
41
40
  # This is just passed to Celluloid.exception_handler which will
42
41
  # push the reiceved block to an array of handlers, by default empty, [].
43
42
  #
44
- # We reraise the exception here casue it's safe and users could have defined
45
- # their own exception handler for SuckerPunch
46
- raise
43
+
44
+ # Do not rescue. SuckerPunch will call the error handler.
47
45
  end
48
46
  end
49
47
  end
@@ -9,7 +9,10 @@ module Rollbar
9
9
  Error = Class.new(StandardError)
10
10
  TimeoutError = Class.new(Error)
11
11
 
12
+ DEFAULT_PRIORITY = 1
13
+
12
14
  class << self
15
+ attr_writer :options
13
16
  attr_reader :reaper
14
17
 
15
18
  def call(payload)
@@ -20,6 +23,10 @@ module Rollbar
20
23
  thread
21
24
  end
22
25
 
26
+ def options
27
+ @options || {}
28
+ end
29
+
23
30
  private
24
31
 
25
32
  def threads
@@ -55,15 +62,23 @@ module Rollbar
55
62
  reaper.join
56
63
  end
57
64
  rescue Timeout::Error
58
- raise TimeoutError, "unable to reap all threads within #{EXIT_TIMEOUT} seconds"
65
+ raise TimeoutError,
66
+ "unable to reap all threads within #{EXIT_TIMEOUT} seconds"
59
67
  end
60
68
  end
61
69
  end
62
- end # class << self
70
+ end
71
+
72
+ def priority
73
+ self.class.options[:priority] || DEFAULT_PRIORITY
74
+ end
63
75
 
64
76
  def call(payload)
77
+ priority = self.priority
78
+
65
79
  ::Thread.new do
66
80
  begin
81
+ ::Thread.current.priority = priority
67
82
  Rollbar.process_from_async_handler(payload)
68
83
  rescue StandardError
69
84
  # Here we swallow the exception:
@@ -1,3 +1,5 @@
1
+ require 'json'
2
+
1
3
  module Rollbar
2
4
  # Deploy Tracking API wrapper module
3
5
  module Deploy
@@ -28,9 +30,7 @@ module Rollbar
28
30
  return {} unless access_token && !access_token.empty?
29
31
 
30
32
  uri = ::URI.parse(
31
- ::Rollbar::Deploy::ENDPOINT +
32
- deploy_id.to_s +
33
- '?access_token=' + access_token
33
+ "#{::Rollbar::Deploy::ENDPOINT}#{deploy_id}?access_token=#{access_token}"
34
34
  )
35
35
 
36
36
  request = ::Net::HTTP::Patch.new(uri.request_uri)
@@ -72,17 +72,18 @@ module Rollbar
72
72
 
73
73
  def request_result(uri, request)
74
74
  {
75
- :request_info => uri.inspect + ': ' + request.body,
75
+ :request_info => "#{uri.inspect}: #{request.body}",
76
76
  :request => request
77
77
  }
78
78
  end
79
79
 
80
80
  def response_result(response)
81
+ code = response.code
82
+ message = response.message
83
+ body = response.body.delete("\n")
81
84
  {
82
85
  :response => response,
83
- :response_info => response.code + '; ' +
84
- response.message + '; ' +
85
- response.body.delete("\n")
86
+ :response_info => "#{code}; #{message}; #{body}"
86
87
  }.merge(::JSON.parse(response.body, :symbolize_names => true))
87
88
  end
88
89
  end
@@ -1,9 +1,10 @@
1
1
  module Rollbar
2
2
  module Encoding
3
3
  class Encoder
4
- ALL_ENCODINGS = [::Encoding::UTF_8, ::Encoding::ISO_8859_1, ::Encoding::ASCII_8BIT, ::Encoding::US_ASCII].freeze
5
- ASCII_ENCODINGS = [::Encoding::US_ASCII, ::Encoding::ASCII_8BIT, ::Encoding::ISO_8859_1].freeze
6
- ENCODING_OPTIONS = { :invalid => :replace, :undef => :replace, :replace => '' }.freeze
4
+ ALL_ENCODINGS = [::Encoding::UTF_8, ::Encoding::ISO_8859_1, ::Encoding::ASCII_8BIT,
5
+ ::Encoding::US_ASCII].freeze
6
+ ASCII_ENCODINGS = [::Encoding::US_ASCII, ::Encoding::ASCII_8BIT,
7
+ ::Encoding::ISO_8859_1].freeze
7
8
  UTF8 = 'UTF-8'.freeze
8
9
  BINARY = 'binary'.freeze
9
10
 
@@ -21,10 +22,19 @@ module Rollbar
21
22
  encoded_value = if encoding == ::Encoding::UTF_8 && value.valid_encoding?
22
23
  value
23
24
  else
24
- force_encoding(value).encode(*encoding_args(value))
25
+ force_encoding(value).encode(
26
+ *encoding_args(value),
27
+ # Ruby 2.7 requires this to look like keyword args,
28
+ # and Ruby 1.9.3 doesn't understand keyword args, so
29
+ # don't use hash rockets here and both will be happy.
30
+ invalid: :replace, undef: :replace, replace: '' # rubocop:disable Style/HashSyntax
31
+ )
25
32
  end
26
33
 
27
34
  object.is_a?(Symbol) ? encoded_value.to_sym : encoded_value
35
+ rescue StandardError => e
36
+ # If encoding fails for any reason, replace the string with a diagnostic error.
37
+ "error encoding string: #{e.class}: #{e.message}"
28
38
  end
29
39
 
30
40
  private
@@ -32,7 +42,9 @@ module Rollbar
32
42
  def force_encoding(value)
33
43
  return value if value.frozen?
34
44
 
35
- value.force_encoding(detect_encoding(value)) if value.encoding == ::Encoding::UTF_8
45
+ if value.encoding == ::Encoding::UTF_8
46
+ value.force_encoding(detect_encoding(value))
47
+ end
36
48
 
37
49
  value
38
50
  end
@@ -54,7 +66,6 @@ module Rollbar
54
66
  def encoding_args(value)
55
67
  args = [UTF8]
56
68
  args << BINARY if ASCII_ENCODINGS.include?(value.encoding)
57
- args << ENCODING_OPTIONS
58
69
 
59
70
  args
60
71
  end
@@ -5,13 +5,8 @@ module Rollbar
5
5
  end
6
6
 
7
7
  def self.setup
8
- if String.instance_methods.include?(:encode)
9
- require 'rollbar/encoding/encoder'
10
- self.encoding_class = Rollbar::Encoding::Encoder
11
- else
12
- require 'rollbar/encoding/legacy_encoder'
13
- self.encoding_class = Rollbar::Encoding::LegacyEncoder
14
- end
8
+ require 'rollbar/encoding/encoder'
9
+ self.encoding_class = Rollbar::Encoding::Encoder
15
10
  end
16
11
 
17
12
  def self.encode(object)
@@ -7,16 +7,23 @@ module Rollbar
7
7
 
8
8
  exception_data = exception_data(exception)
9
9
 
10
- if exception_data.is_a?(Hash)
10
+ case exception_data
11
+ when Hash
11
12
  env['rollbar.exception_uuid'] = exception_data[:uuid]
12
- Rollbar.log_debug "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
13
- elsif exception_data == 'disabled'
14
- Rollbar.log_debug '[Rollbar] Exception not reported because Rollbar is disabled'
15
- elsif exception_data == 'ignored'
13
+ Rollbar.log_debug(
14
+ "[Rollbar] Exception uuid saved in env: #{exception_data[:uuid]}"
15
+ )
16
+ when 'disabled'
17
+ Rollbar.log_debug(
18
+ '[Rollbar] Exception not reported because Rollbar is disabled'
19
+ )
20
+ when 'ignored'
16
21
  Rollbar.log_debug '[Rollbar] Exception not reported because it was ignored'
17
22
  end
18
23
  rescue StandardError => e
19
- Rollbar.log_warning "[Rollbar] Exception while reporting exception to Rollbar: #{e.message}"
24
+ Rollbar.log_warning(
25
+ "[Rollbar] Exception while reporting exception to Rollbar: #{e.message}"
26
+ )
20
27
  end
21
28
 
22
29
  def capture_uncaught?
@@ -24,12 +31,14 @@ module Rollbar
24
31
  end
25
32
 
26
33
  def log_exception_message(exception)
27
- exception_message = exception.respond_to?(:message) ? exception.message : 'No Exception Message'
34
+ exception_message = exception.message if exception.respond_to?(:message)
35
+ exception_message ||= 'No Exception Message'
28
36
  Rollbar.log_debug "[Rollbar] Reporting exception: #{exception_message}"
29
37
  end
30
38
 
31
39
  def exception_data(exception)
32
- Rollbar.log(Rollbar.configuration.uncaught_exception_level, exception, :use_exception_level_filters => true)
40
+ Rollbar.log(Rollbar.configuration.uncaught_exception_level, exception,
41
+ :use_exception_level_filters => true)
33
42
  end
34
43
  end
35
44
  end