rollbar 2.22.1 → 2.27.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/.github/pull_request_template.md +25 -0
  3. data/.rubocop.yml +136 -0
  4. data/.travis.yml +33 -30
  5. data/Gemfile +2 -0
  6. data/README.md +1 -1
  7. data/data/rollbar.snippet.js +1 -1
  8. data/docs/configuration.md +8 -0
  9. data/gemfiles/rails42.gemfile +4 -0
  10. data/gemfiles/rails50.gemfile +6 -2
  11. data/gemfiles/rails51.gemfile +6 -2
  12. data/gemfiles/rails60.gemfile +1 -1
  13. data/lib/rails/rollbar_runner.rb +3 -1
  14. data/lib/rollbar/capistrano.rb +1 -1
  15. data/lib/rollbar/capistrano_tasks.rb +10 -1
  16. data/lib/rollbar/configuration.rb +28 -6
  17. data/lib/rollbar/delay/girl_friday.rb +3 -7
  18. data/lib/rollbar/delay/resque.rb +2 -3
  19. data/lib/rollbar/delay/sidekiq.rb +2 -4
  20. data/lib/rollbar/delay/sucker_punch.rb +3 -4
  21. data/lib/rollbar/delay/thread.rb +14 -0
  22. data/lib/rollbar/deploy.rb +2 -0
  23. data/lib/rollbar/encoding/encoder.rb +10 -3
  24. data/lib/rollbar/item/backtrace.rb +12 -2
  25. data/lib/rollbar/item/frame.rb +2 -0
  26. data/lib/rollbar/item/locals.rb +45 -1
  27. data/lib/rollbar/item.rb +22 -14
  28. data/lib/rollbar/json.rb +1 -0
  29. data/lib/rollbar/middleware/js.rb +13 -3
  30. data/lib/rollbar/notifier.rb +154 -61
  31. data/lib/rollbar/plugins/active_job.rb +6 -2
  32. data/lib/rollbar/plugins/delayed_job/plugin.rb +11 -1
  33. data/lib/rollbar/plugins/error_context.rb +11 -0
  34. data/lib/rollbar/rake_tasks.rb +1 -1
  35. data/lib/rollbar/request_data_extractor.rb +7 -1
  36. data/lib/rollbar/rollbar_test.rb +6 -117
  37. data/lib/rollbar/scrubbers/url.rb +10 -5
  38. data/lib/rollbar/scrubbers.rb +1 -5
  39. data/lib/rollbar/truncation/frames_strategy.rb +1 -1
  40. data/lib/rollbar/truncation/mixin.rb +1 -1
  41. data/lib/rollbar/truncation/strings_strategy.rb +4 -2
  42. data/lib/rollbar/util.rb +4 -0
  43. data/lib/rollbar/version.rb +1 -1
  44. data/rollbar.gemspec +1 -0
  45. data/spec/support/rollbar_api.rb +67 -0
  46. metadata +6 -4
@@ -19,7 +19,9 @@ module Rollbar
19
19
  attr_accessor :last_report
20
20
  attr_accessor :scope_object
21
21
 
22
- @file_semaphore = Mutex.new
22
+ MUTEX = Mutex.new
23
+ EXTENSION_REGEXP = /.rollbar\z/.freeze
24
+ FAILSAFE_STRING_LENGTH = 10_000
23
25
 
24
26
  def initialize(parent_notifier = nil, payload_options = nil, scope = nil)
25
27
  if parent_notifier
@@ -103,10 +105,10 @@ module Rollbar
103
105
 
104
106
  # Sends a report to Rollbar.
105
107
  #
106
- # Accepts any number of arguments. The last String argument will become
107
- # the message or description of the report. The last Exception argument
108
- # will become the associated exception for the report. The last hash
109
- # argument will be used as the extra data for the report.
108
+ # Accepts a level string plus any number of arguments. The last String
109
+ # argument will become the message or description of the report. The last
110
+ # Exception argument will become the associated exception for the report.
111
+ # The last hash argument will be used as the extra data for the report.
110
112
  #
111
113
  # If the extra hash contains a symbol key :custom_data_method_context
112
114
  # the value of the key will be used as the context for
@@ -117,14 +119,14 @@ module Rollbar
117
119
  # begin
118
120
  # foo = bar
119
121
  # rescue => e
120
- # Rollbar.log(e)
122
+ # Rollbar.log('error', e)
121
123
  # end
122
124
  #
123
125
  # @example
124
- # Rollbar.log('This is a simple log message')
126
+ # Rollbar.log('info', 'This is a simple log message')
125
127
  #
126
128
  # @example
127
- # Rollbar.log(e, 'This is a description of the exception')
129
+ # Rollbar.log('error', e, 'This is a description of the exception')
128
130
  #
129
131
  def log(level, *args)
130
132
  return 'disabled' unless enabled?
@@ -157,7 +159,13 @@ module Rollbar
157
159
  def report_with_rescue(level, message, exception, extra, context)
158
160
  report(level, message, exception, extra, context)
159
161
  rescue StandardError, SystemStackError => e
160
- report_internal_error(e)
162
+ original_error = {
163
+ :message => message,
164
+ :exception => exception,
165
+ :configuration => configuration
166
+ }
167
+
168
+ report_internal_error(e, original_error)
161
169
 
162
170
  'error'
163
171
  end
@@ -200,18 +208,20 @@ module Rollbar
200
208
  def process_item(item)
201
209
  if configuration.write_to_file
202
210
  if configuration.use_async
203
- @file_semaphore.synchronize do
204
- write_item(item)
211
+ MUTEX.synchronize do
212
+ do_write_item(item)
205
213
  end
206
214
  else
207
- write_item(item)
215
+ do_write_item(item)
208
216
  end
209
217
  else
210
218
  send_item(item)
211
219
  end
212
220
  rescue StandardError => e
213
221
  log_error("[Rollbar] Error processing the item: #{e.class}, #{e.message}. Item: #{item.payload.inspect}")
214
- raise e
222
+ raise e unless via_failsafe?(item)
223
+
224
+ log_error('[Rollbar] Item has already failed. Not re-raising')
215
225
  end
216
226
 
217
227
  # We will reraise exceptions in this method so async queues
@@ -238,16 +248,19 @@ module Rollbar
238
248
  # Using Rollbar.silenced we avoid the above behavior but Sidekiq
239
249
  # will have a chance to retry the original job.
240
250
  def process_from_async_handler(payload)
241
- payload = Rollbar::JSON.load(payload) if payload.is_a?(String)
242
-
243
- item = Item.build_with(payload,
244
- :notifier => self,
245
- :configuration => configuration,
246
- :logger => logger)
247
-
248
251
  Rollbar.silenced do
249
252
  begin
250
- process_item(item)
253
+ if payload.is_a?(String)
254
+ # The final payload has already been built.
255
+ send_body(payload)
256
+ else
257
+ item = Item.build_with(payload,
258
+ :notifier => self,
259
+ :configuration => configuration,
260
+ :logger => logger)
261
+
262
+ process_item(item)
263
+ end
251
264
  rescue StandardError => e
252
265
  report_internal_error(e)
253
266
 
@@ -256,35 +269,34 @@ module Rollbar
256
269
  end
257
270
  end
258
271
 
259
- def send_failsafe(message, exception, uuid = nil, host = nil)
260
- exception_reason = failsafe_reason(message, exception)
261
-
262
- log_error "[Rollbar] Sending failsafe response due to #{exception_reason}"
263
-
264
- body = failsafe_body(exception_reason)
265
-
266
- failsafe_data = {
272
+ def failsafe_initial_data(exception_reason)
273
+ {
267
274
  :level => 'error',
268
275
  :environment => configuration.environment.to_s,
269
276
  :body => {
270
277
  :message => {
271
- :body => body
278
+ :body => failsafe_body(exception_reason)
272
279
  }
273
280
  },
274
281
  :notifier => {
275
282
  :name => 'rollbar-gem',
276
283
  :version => VERSION
277
284
  },
278
- :custom => {
279
- :orig_uuid => uuid,
280
- :orig_host => host
281
- },
282
285
  :internal => true,
283
- :failsafe => true
286
+ 'failsafe' => true
284
287
  }
288
+ end
289
+
290
+ def send_failsafe(message, exception, original_error = nil)
291
+ exception_reason = failsafe_reason(message, exception)
292
+
293
+ log_error "[Rollbar] Sending failsafe response due to #{exception_reason}"
294
+
295
+ failsafe_data = failsafe_initial_data(exception_reason)
296
+
297
+ failsafe_add_original_error_data(failsafe_data[:notifier], original_error)
285
298
 
286
299
  failsafe_payload = {
287
- 'access_token' => configuration.access_token,
288
300
  'data' => failsafe_data
289
301
  }
290
302
 
@@ -293,7 +305,9 @@ module Rollbar
293
305
  :notifier => self,
294
306
  :configuration => configuration,
295
307
  :logger => logger)
296
- schedule_item(item)
308
+
309
+ process_item(item)
310
+ log_and_return_item_data(item)
297
311
  rescue StandardError => e
298
312
  log_error "[Rollbar] Error sending failsafe : #{e}"
299
313
  end
@@ -301,6 +315,57 @@ module Rollbar
301
315
  failsafe_payload
302
316
  end
303
317
 
318
+ def failsafe_add_original_error_data(payload_notifier, original_error)
319
+ return unless original_error
320
+
321
+ payload_notifier[:diagnostic] ||= {}
322
+
323
+ add_original_host(payload_notifier[:diagnostic], original_error)
324
+ add_original_uuid(payload_notifier[:diagnostic], original_error)
325
+ add_original_message(payload_notifier[:diagnostic], original_error)
326
+ add_original_error(payload_notifier[:diagnostic], original_error)
327
+ add_configured_options(payload_notifier, original_error)
328
+ end
329
+
330
+ def add_original_message(diagnostic, original_error)
331
+ diagnostic[:original_message] = original_error[:message].truncate(FAILSAFE_STRING_LENGTH) if original_error[:message]
332
+
333
+ rescue StandardError => e
334
+ diagnostic[:original_message] = "Failed: #{e.message}"
335
+ end
336
+
337
+ def add_original_error(diagnostic, original_error)
338
+ if original_error[:exception]
339
+ backtrace = original_error[:exception].backtrace
340
+ message = original_error[:exception].message
341
+ diagnostic[:original_error] = {
342
+ :message => message && message.truncate(FAILSAFE_STRING_LENGTH),
343
+ :stack => backtrace && backtrace.join(', ').truncate(FAILSAFE_STRING_LENGTH)
344
+ }
345
+ end
346
+
347
+ rescue StandardError => e
348
+ diagnostic[:original_error] = "Failed: #{e.message}"
349
+ end
350
+
351
+ def add_configured_options(payload_notifier, original_error)
352
+ if original_error[:configuration]
353
+ configured = original_error[:configuration].configured_options.configured
354
+ payload_notifier[:configured_options] = ::JSON.generate(configured).truncate(FAILSAFE_STRING_LENGTH)
355
+ end
356
+
357
+ rescue StandardError => e
358
+ payload_notifier[:configured_options] = "Failed: #{e.message}"
359
+ end
360
+
361
+ def add_original_host(diagnostic, original_error)
362
+ diagnostic[:original_host] = original_error[:host] if original_error[:host]
363
+ end
364
+
365
+ def add_original_uuid(diagnostic, original_error)
366
+ diagnostic[:original_uuid] = original_error[:uuid] if original_error[:uuid]
367
+ end
368
+
304
369
  ## Logging
305
370
  %w[debug info warn error].each do |level|
306
371
  define_method(:"log_#{level}") do |message|
@@ -456,7 +521,7 @@ module Rollbar
456
521
  # Reports an internal error in the Rollbar library. This will be reported within the configured
457
522
  # Rollbar project. We'll first attempt to provide a report including the exception traceback.
458
523
  # If that fails, we'll fall back to a more static failsafe response.
459
- def report_internal_error(exception)
524
+ def report_internal_error(exception, original_error = nil)
460
525
  log_error '[Rollbar] Reporting internal error encountered while sending data to Rollbar.'
461
526
 
462
527
  configuration.execute_hook(:on_report_internal_error, exception)
@@ -464,7 +529,7 @@ module Rollbar
464
529
  begin
465
530
  item = build_item('error', nil, exception, { :internal => true }, nil)
466
531
  rescue StandardError => e
467
- send_failsafe('build_item in exception_data', e)
532
+ send_failsafe('build_item in exception_data', e, original_error)
468
533
  log_error "[Rollbar] Exception: #{exception}"
469
534
  return
470
535
  end
@@ -472,7 +537,7 @@ module Rollbar
472
537
  begin
473
538
  process_item(item)
474
539
  rescue StandardError => e
475
- send_failsafe('error in process_item', e)
540
+ send_failsafe('error in process_item', e, original_error)
476
541
  log_error "[Rollbar] Item: #{item}"
477
542
  return
478
543
  end
@@ -480,7 +545,7 @@ module Rollbar
480
545
  begin
481
546
  log_instance_link(item['data'])
482
547
  rescue StandardError => e
483
- send_failsafe('error logging instance link', e)
548
+ send_failsafe('error logging instance link', e, original_error)
484
549
  log_error "[Rollbar] Item: #{item}"
485
550
  return
486
551
  end
@@ -509,14 +574,18 @@ module Rollbar
509
574
 
510
575
  ## Delivery functions
511
576
 
512
- def send_item_using_eventmachine(item, uri)
513
- body = item.dump
514
- return unless body
577
+ def send_using_eventmachine(body)
578
+ uri = URI.parse(configuration.endpoint)
515
579
 
516
- headers = { 'X-Rollbar-Access-Token' => item['access_token'] }
580
+ headers = { 'X-Rollbar-Access-Token' => configuration.access_token }
517
581
  options = http_proxy_for_em(uri)
518
582
  req = EventMachine::HttpRequest.new(uri.to_s, options).post(:body => body, :head => headers)
519
583
 
584
+ eventmachine_callback(req)
585
+ eventmachine_errback(req)
586
+ end
587
+
588
+ def eventmachine_callback(req)
520
589
  req.callback do
521
590
  if req.response_header.status == 200
522
591
  log_info '[Rollbar] Success'
@@ -525,7 +594,9 @@ module Rollbar
525
594
  log_info "[Rollbar] Response: #{req.response}"
526
595
  end
527
596
  end
597
+ end
528
598
 
599
+ def eventmachine_errback(req)
529
600
  req.errback do
530
601
  log_warning "[Rollbar] Call to API failed, status code: #{req.response_header.status}"
531
602
  log_info "[Rollbar] Error's response: #{req.response}"
@@ -538,14 +609,20 @@ module Rollbar
538
609
  body = item.dump
539
610
  return unless body
540
611
 
541
- uri = URI.parse(configuration.endpoint)
542
-
543
612
  if configuration.use_eventmachine
544
- send_item_using_eventmachine(item, uri)
613
+ send_using_eventmachine(body)
545
614
  return
546
615
  end
547
616
 
548
- handle_response(do_post(uri, body, item['access_token']))
617
+ send_body(body)
618
+ end
619
+
620
+ def send_body(body)
621
+ log_info '[Rollbar] Sending json'
622
+
623
+ uri = URI.parse(configuration.endpoint)
624
+
625
+ handle_response(do_post(uri, body, configuration.access_token))
549
626
  end
550
627
 
551
628
  def do_post(uri, body, access_token)
@@ -658,27 +735,24 @@ module Rollbar
658
735
  end
659
736
  end
660
737
 
661
- def write_item(item)
662
- if configuration.use_async
663
- @file_semaphore.synchronize do
664
- do_write_item(item)
665
- end
666
- else
667
- do_write_item(item)
668
- end
669
- end
670
-
671
738
  def do_write_item(item)
672
739
  log_info '[Rollbar] Writing item to file'
673
740
 
674
741
  body = item.dump
675
742
  return unless body
676
743
 
744
+ file_name = if configuration.files_with_pid_name_enabled
745
+ configuration.filepath.gsub(EXTENSION_REGEXP, "_#{Process.pid}\\0")
746
+ else
747
+ configuration.filepath
748
+ end
749
+
677
750
  begin
678
- @file ||= File.open(configuration.filepath, 'a')
751
+ @file ||= File.open(file_name, 'a')
679
752
 
680
753
  @file.puts(body)
681
754
  @file.flush
755
+ update_file(@file, file_name)
682
756
 
683
757
  log_info '[Rollbar] Success'
684
758
  rescue IOError => e
@@ -686,6 +760,18 @@ module Rollbar
686
760
  end
687
761
  end
688
762
 
763
+ def update_file(file, file_name)
764
+ return unless configuration.files_processed_enabled
765
+
766
+ time_now = Time.now
767
+ return if configuration.files_processed_duration > time_now - file.birthtime && file.size < configuration.files_processed_size
768
+
769
+ new_file_name = file_name.gsub(EXTENSION_REGEXP, "_processed_#{time_now.to_i}\\0")
770
+ File.rename(file, new_file_name)
771
+ file.close
772
+ @file = File.open(file_name, 'a')
773
+ end
774
+
689
775
  def failsafe_reason(message, exception)
690
776
  body = ''
691
777
 
@@ -737,8 +823,11 @@ module Rollbar
737
823
  end
738
824
 
739
825
  def process_async_item(item)
826
+ # Send async payloads as JSON string when async_json_payload is set.
827
+ payload = configuration.async_json_payload ? item.dump : item.payload
828
+
740
829
  configuration.async_handler ||= default_async_handler
741
- configuration.async_handler.call(item.payload)
830
+ configuration.async_handler.call(payload)
742
831
  rescue StandardError
743
832
  if configuration.failover_handlers.empty?
744
833
  log_error '[Rollbar] Async handler failed, and there are no failover handlers configured. See the docs for "failover_handlers"'
@@ -772,5 +861,9 @@ module Rollbar
772
861
  uuid_url = Util.uuid_rollbar_url(data, configuration)
773
862
  log_info "[Rollbar] Details: #{uuid_url} (only available if report was successful)"
774
863
  end
864
+
865
+ def via_failsafe?(item)
866
+ item.payload.fetch('data', {}).fetch('failsafe', false)
867
+ end
775
868
  end
776
869
  end
@@ -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
@@ -12,7 +12,13 @@ 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
+ ::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
@@ -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
@@ -1,6 +1,6 @@
1
1
 
2
2
  namespace :rollbar do
3
- 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'
4
4
  task :test => [:environment] do
5
5
  rollbar_dir = Gem.loaded_specs['rollbar'].full_gem_path
6
6
  require "#{rollbar_dir}/lib/rollbar/rollbar_test"
@@ -131,6 +131,7 @@ module Rollbar
131
131
  host = host.split(',').first.strip unless host.empty?
132
132
 
133
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?}"
134
135
  unless path.nil? || path.empty?
135
136
  path = '/' + path.to_s if path.to_s.slice(0, 1) != '/'
136
137
  end
@@ -247,7 +248,12 @@ module Rollbar
247
248
  end
248
249
 
249
250
  def sensitive_headers_list
250
- 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
251
257
  end
252
258
  end
253
259
  end
@@ -1,48 +1,16 @@
1
1
  require 'rollbar'
2
- begin
3
- require 'rack/mock'
4
- rescue LoadError
5
- puts 'Cannot load rack/mock'
6
- end
7
- require 'logger'
8
2
 
9
- # Module to inject into the Rails controllers or rack apps
10
3
  module RollbarTest # :nodoc:
11
- def test_rollbar
12
- puts 'Raising RollbarTestingException to simulate app failure.'
13
-
14
- raise RollbarTestingException.new, ::RollbarTest.success_message
15
- end
16
-
17
4
  def self.run
18
5
  return unless confirmed_token?
19
6
 
20
- configure_rails if defined?(Rails)
21
-
22
- puts 'Testing manual report...'
23
- Rollbar.error('Test error from rollbar:test')
24
-
25
- return unless defined?(Rack::MockRequest)
26
-
27
- protocol, app = setup_app
28
-
29
- puts 'Processing...'
30
- env = Rack::MockRequest.env_for("#{protocol}://www.example.com/verify", 'REMOTE_ADDR' => '127.0.0.1')
31
- status, = app.call(env)
32
-
33
- puts error_message unless status.to_i == 500
34
- end
35
-
36
- def self.configure_rails
37
- Rails.logger = if defined?(ActiveSupport::TaggedLogging)
38
- ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
39
- else
40
- Logger.new(STDOUT)
41
- end
7
+ puts 'Test sending to Rollbar...'
8
+ result = Rollbar.info('Test message from rollbar:test')
42
9
 
43
- Rails.logger.level = Logger::DEBUG
44
- Rollbar.preconfigure do |config|
45
- config.logger = Rails.logger
10
+ if result == 'error'
11
+ puts error_message
12
+ else
13
+ puts success_message
46
14
  end
47
15
  end
48
16
 
@@ -54,69 +22,6 @@ module RollbarTest # :nodoc:
54
22
  false
55
23
  end
56
24
 
57
- def self.authlogic_config
58
- # from http://stackoverflow.com/questions/5270835/authlogic-activation-problems
59
- return unless defined?(Authlogic)
60
-
61
- Authlogic::Session::Base.controller = Authlogic::ControllerAdapters::RailsAdapter.new(self)
62
- end
63
-
64
- def self.setup_app
65
- puts 'Setting up the test app.'
66
-
67
- if defined?(Rails)
68
- app = rails_app
69
-
70
- draw_rails_route(app)
71
-
72
- authlogic_config
73
-
74
- [rails_protocol(app), app]
75
- else
76
- ['http', rack_app]
77
- end
78
- end
79
-
80
- def self.rails_app
81
- # The setup below is needed for Rails 5.x, but not for Rails 4.x and below.
82
- # (And fails on Rails 4.x in various ways depending on the exact version.)
83
- return Rails.application if Rails.version < '5.0.0'
84
-
85
- # Spring now runs by default in development on all new Rails installs. This causes
86
- # the new `/verify` route to not get picked up if `config.cache_classes == false`
87
- # which is also a default in development env.
88
- #
89
- # `config.cache_classes` needs to be set, but the only possible time is at app load,
90
- # so here we clone the default app with an updated config.
91
- #
92
- config = Rails.application.config
93
- config.cache_classes = true
94
-
95
- # Make a copy of the app, so the config can be updated.
96
- Rails.application.class.name.constantize.new(:config => config)
97
- end
98
-
99
- def self.draw_rails_route(app)
100
- app.routes_reloader.execute_if_updated
101
- app.routes.draw do
102
- get 'verify' => 'rollbar_test#verify', :as => 'verify'
103
- end
104
- end
105
-
106
- def self.rails_protocol(app)
107
- defined?(app.config.force_ssl && app.config.force_ssl) ? 'https' : 'http'
108
- end
109
-
110
- def self.rack_app
111
- Class.new do
112
- include RollbarTest
113
-
114
- def self.call(_env)
115
- new.test_rollbar
116
- end
117
- end
118
- end
119
-
120
25
  def self.token_error_message
121
26
  'Rollbar needs an access token configured. Check the README for instructions.'
122
27
  end
@@ -129,19 +34,3 @@ module RollbarTest # :nodoc:
129
34
  'Testing rollbar with "rake rollbar:test". If you can see this, it works.'
130
35
  end
131
36
  end
132
-
133
- class RollbarTestingException < RuntimeError; end
134
-
135
- if defined?(Rails)
136
- class RollbarTestController < ActionController::Base # :nodoc:
137
- include RollbarTest
138
-
139
- def verify
140
- test_rollbar
141
- end
142
-
143
- def logger
144
- nil
145
- end
146
- end
147
- end
@@ -67,10 +67,7 @@ module Rollbar
67
67
 
68
68
  params = decode_www_form(query)
69
69
 
70
- encoded_query = encode_www_form(filter_query_params(params, regex, randomize_scrub_length, scrub_all, whitelist))
71
-
72
- # We want this to rebuild array params like foo[]=1&foo[]=2
73
- URI.escape(CGI.unescape(encoded_query))
70
+ encode_www_form(filter_query_params(params, regex, randomize_scrub_length, scrub_all, whitelist))
74
71
  end
75
72
 
76
73
  def decode_www_form(query)
@@ -78,7 +75,15 @@ module Rollbar
78
75
  end
79
76
 
80
77
  def encode_www_form(params)
81
- URI.encode_www_form(params)
78
+ restore_square_brackets(URI.encode_www_form(params))
79
+ end
80
+
81
+ def restore_square_brackets(query)
82
+ # We want this to rebuild array params like foo[]=1&foo[]=2
83
+ #
84
+ # URI.encode_www_form follows the spec at https://url.spec.whatwg.org/#concept-urlencoded-serializer
85
+ # and percent encodes square brackets. Here we change them back.
86
+ query.gsub('%5B', '[').gsub('%5D', ']')
82
87
  end
83
88
 
84
89
  def filter_query_params(params, regex, randomize_scrub_length, scrub_all, whitelist)
@@ -6,11 +6,7 @@ module Rollbar
6
6
  if Rollbar.configuration.randomize_scrub_length
7
7
  random_filtered_value
8
8
  else
9
- '*' * (begin
10
- value.length
11
- rescue StandardError
12
- 8
13
- end)
9
+ '*' * 6
14
10
  end
15
11
  end
16
12
 
@@ -11,7 +11,7 @@ module Rollbar
11
11
  end
12
12
 
13
13
  def call(payload)
14
- new_payload = Rollbar::Util.deep_copy(payload)
14
+ new_payload = payload
15
15
  body = new_payload['data']['body']
16
16
 
17
17
  if body['trace_chain']
@@ -9,7 +9,7 @@ module Rollbar
9
9
  result.bytesize > MAX_PAYLOAD_SIZE
10
10
  end
11
11
 
12
- def select_frames(frames, range = 150)
12
+ def select_frames(frames, range = 50)
13
13
  return frames unless frames.count > range * 2
14
14
 
15
15
  frames[0, range] + frames[-range, range]