rollbar 2.19.3 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -0
  3. data/.travis.yml +42 -16
  4. data/Gemfile +31 -14
  5. data/data/rollbar.snippet.js +1 -1
  6. data/docs/configuration.md +9 -0
  7. data/gemfiles/rails30.gemfile +8 -10
  8. data/gemfiles/rails31.gemfile +8 -9
  9. data/gemfiles/rails32.gemfile +8 -9
  10. data/gemfiles/rails40.gemfile +8 -9
  11. data/gemfiles/rails41.gemfile +8 -9
  12. data/gemfiles/rails42.gemfile +8 -11
  13. data/gemfiles/rails50.gemfile +13 -12
  14. data/gemfiles/rails51.gemfile +13 -12
  15. data/gemfiles/rails52.gemfile +13 -12
  16. data/gemfiles/rails60.gemfile +67 -0
  17. data/lib/rails/rollbar_runner.rb +1 -1
  18. data/lib/rollbar/configuration.rb +11 -1
  19. data/lib/rollbar/item.rb +15 -6
  20. data/lib/rollbar/json.rb +2 -51
  21. data/lib/rollbar/language_support.rb +3 -19
  22. data/lib/rollbar/logger_proxy.rb +5 -1
  23. data/lib/rollbar/notifier.rb +23 -10
  24. data/lib/rollbar/plugins/basic_socket.rb +1 -1
  25. data/lib/rollbar/rake_tasks.rb +3 -147
  26. data/lib/rollbar/request_data_extractor.rb +3 -2
  27. data/lib/rollbar/rollbar_test.rb +147 -0
  28. data/lib/rollbar/scrubbers/params.rb +2 -2
  29. data/lib/rollbar/scrubbers/url.rb +0 -1
  30. data/lib/rollbar/truncation.rb +9 -2
  31. data/lib/rollbar/truncation/min_body_strategy.rb +2 -3
  32. data/lib/rollbar/truncation/remove_any_key_strategy.rb +123 -0
  33. data/lib/rollbar/truncation/remove_extra_strategy.rb +35 -0
  34. data/lib/rollbar/truncation/remove_request_strategy.rb +21 -0
  35. data/lib/rollbar/truncation/strings_strategy.rb +2 -3
  36. data/lib/rollbar/util.rb +2 -2
  37. data/lib/rollbar/util/hash.rb +15 -0
  38. data/lib/rollbar/version.rb +1 -1
  39. data/rollbar.gemspec +0 -2
  40. metadata +10 -21
  41. data/gemfiles/ruby_1_8_and_1_9_2.gemfile +0 -51
  42. data/lib/rollbar/json/default.rb +0 -11
  43. data/lib/rollbar/json/oj.rb +0 -16
@@ -2,12 +2,19 @@ require 'rubygems/version'
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ # Used by spec/commands/rollbar_rails_runner_spec, and can be used whenever a
6
+ # new process is created during tests. (Testing rake tasks, for example.)
7
+ # This is a workaround for ENV['BUNDLE_GEMFILE'] not working as expected on Travis.
8
+ # We use the ||= assignment because Travis loads the gemfile twice, the second time
9
+ # with the wrong gemfile path.
10
+ ENV['CURRENT_GEMFILE'] ||= __FILE__
11
+
5
12
  is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
6
13
 
7
14
  gem 'appraisal'
8
15
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
9
16
  gem 'jruby-openssl', :platform => :jruby
10
- gem 'rails', '~> 5.0.0'
17
+ gem 'rails', '~> 5.0.7'
11
18
  gem 'sqlite3', '< 1.4.0', :platform => [:ruby, :mswin, :mingw]
12
19
 
13
20
  gem 'rspec-core', '~> 3.5.0.beta3'
@@ -20,16 +27,6 @@ gem 'rake'
20
27
 
21
28
  gem 'sidekiq', '>= 2.13.0'
22
29
 
23
- unless is_jruby
24
- if RUBY_VERSION >= '2.5'
25
- gem 'oj'
26
- elsif RUBY_VERSION >= '2.4.0'
27
- gem 'oj', '~> 2.16.1'
28
- else
29
- gem 'oj', '~> 2.12.14'
30
- end
31
- end
32
-
33
30
  platforms :rbx do
34
31
  gem 'minitest'
35
32
  gem 'racc'
@@ -53,10 +50,14 @@ gem 'database_cleaner'
53
50
  gem 'delayed_job', :require => false
54
51
  gem 'generator_spec'
55
52
  gem 'girl_friday', '>= 0.11.1'
56
- gem 'rspec-command'
57
53
  gem 'redis'
58
54
  gem 'resque'
59
55
 
56
+ unless is_jruby
57
+ # JRuby doesn't support fork, which is required for this test helper.
58
+ gem 'rspec-command'
59
+ end
60
+
60
61
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0')
61
62
  gem 'mime-types', '< 3.0'
62
63
  end
@@ -2,12 +2,19 @@ require 'rubygems/version'
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ # Used by spec/commands/rollbar_rails_runner_spec, and can be used whenever a
6
+ # new process is created during tests. (Testing rake tasks, for example.)
7
+ # This is a workaround for ENV['BUNDLE_GEMFILE'] not working as expected on Travis.
8
+ # We use the ||= assignment because Travis loads the gemfile twice, the second time
9
+ # with the wrong gemfile path.
10
+ ENV['CURRENT_GEMFILE'] ||= __FILE__
11
+
5
12
  is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
6
13
 
7
14
  gem 'appraisal'
8
15
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
9
16
  gem 'jruby-openssl', :platform => :jruby
10
- gem 'rails', '~> 5.1.0'
17
+ gem 'rails', '~> 5.1.7'
11
18
  gem 'sqlite3', '< 1.4.0', :platform => [:ruby, :mswin, :mingw]
12
19
 
13
20
  gem 'rspec-core', '~> 3.5.0.beta3'
@@ -20,16 +27,6 @@ gem 'rake'
20
27
 
21
28
  gem 'sidekiq', '>= 2.13.0'
22
29
 
23
- unless is_jruby
24
- if RUBY_VERSION >= '2.5'
25
- gem 'oj'
26
- elsif RUBY_VERSION >= '2.4.0'
27
- gem 'oj', '~> 2.16.1'
28
- else
29
- gem 'oj', '~> 2.12.14'
30
- end
31
- end
32
-
33
30
  platforms :rbx do
34
31
  gem 'minitest'
35
32
  gem 'racc'
@@ -54,10 +51,14 @@ gem 'database_cleaner'
54
51
  gem 'delayed_job', :require => false
55
52
  gem 'generator_spec'
56
53
  gem 'girl_friday', '>= 0.11.1'
57
- gem 'rspec-command'
58
54
  gem 'redis'
59
55
  gem 'resque'
60
56
 
57
+ unless is_jruby
58
+ # JRuby doesn't support fork, which is required for this test helper.
59
+ gem 'rspec-command'
60
+ end
61
+
61
62
  if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.0')
62
63
  gem 'mime-types', '< 3.0'
63
64
  end
@@ -2,12 +2,19 @@ require 'rubygems/version'
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
+ # Used by spec/commands/rollbar_rails_runner_spec, and can be used whenever a
6
+ # new process is created during tests. (Testing rake tasks, for example.)
7
+ # This is a workaround for ENV['BUNDLE_GEMFILE'] not working as expected on Travis.
8
+ # We use the ||= assignment because Travis loads the gemfile twice, the second time
9
+ # with the wrong gemfile path.
10
+ ENV['CURRENT_GEMFILE'] ||= __FILE__
11
+
5
12
  is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
6
13
 
7
14
  gem 'appraisal'
8
15
  gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
9
16
  gem 'jruby-openssl', :platform => :jruby
10
- gem 'rails', '~> 5.2.0'
17
+ gem 'rails', '~> 5.2.3'
11
18
  gem 'sqlite3', '< 1.4.0', :platform => [:ruby, :mswin, :mingw]
12
19
 
13
20
  gem 'rspec-core', '~> 3.8.0'
@@ -18,16 +25,6 @@ gem 'rspec-mocks', '~> 3.8.0'
18
25
 
19
26
  gem 'rake'
20
27
 
21
- unless is_jruby
22
- if RUBY_VERSION >= '2.5'
23
- gem 'oj'
24
- elsif RUBY_VERSION >= '2.4.0'
25
- gem 'oj', '~> 2.16.1'
26
- else
27
- gem 'oj', '~> 2.12.14'
28
- end
29
- end
30
-
31
28
  gem 'sidekiq', '>= 2.13.0'
32
29
 
33
30
  platforms :rbx do
@@ -47,11 +44,15 @@ gem 'codacy-coverage'
47
44
  gem 'delayed_job', :require => false
48
45
  gem 'generator_spec'
49
46
  gem 'girl_friday', '>= 0.11.1'
50
- gem 'rspec-command'
51
47
  gem 'redis'
52
48
  gem 'resque'
53
49
  gem 'simplecov'
54
50
 
51
+ unless is_jruby
52
+ # JRuby doesn't support fork, which is required for this test helper.
53
+ gem 'rspec-command'
54
+ end
55
+
55
56
  gem 'mime-types'
56
57
 
57
58
  gem 'webmock', :require => false
@@ -0,0 +1,67 @@
1
+
2
+ require 'rubygems/version'
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ # Used by spec/commands/rollbar_rails_runner_spec, and can be used whenever a
7
+ # new process is created during tests. (Testing rake tasks, for example.)
8
+ # This is a workaround for ENV['BUNDLE_GEMFILE'] not working as expected on Travis.
9
+ # We use the ||= assignment because Travis loads the gemfile twice, the second time
10
+ # with the wrong gemfile path.
11
+ ENV['CURRENT_GEMFILE'] ||= __FILE__
12
+
13
+ is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
14
+
15
+ gem 'appraisal'
16
+ gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
17
+ gem 'jruby-openssl', :platform => :jruby
18
+ gem 'rails', '6.0.0.rc1'
19
+ gem 'sqlite3', '~> 1.4', :platform => [:ruby, :mswin, :mingw]
20
+
21
+ gem 'rspec-core', '~> 3.8.0'
22
+ gem 'rspec-support', '~> 3.8.0'
23
+ gem 'rspec-expectations', '~> 3.8.0'
24
+ gem 'rspec-mocks', '~> 3.8.0'
25
+ # TODO: update this when 4.x becomes available on Rubygems
26
+ gem 'rspec-rails', :git => 'https://github.com/rspec/rspec-rails', :ref => 'v4.0.0.beta2' # rubocop:disable Bundler/DuplicatedGem
27
+
28
+ gem 'rake'
29
+
30
+ gem 'sidekiq', '>= 2.13.0'
31
+
32
+ platforms :rbx do
33
+ gem 'minitest'
34
+ gem 'racc'
35
+ gem 'rubinius-developer_tools'
36
+ gem 'rubysl', '~> 2.0' unless RUBY_VERSION.start_with?('1')
37
+ end
38
+
39
+ gem 'sucker_punch', '~> 2.0'
40
+
41
+ # We need last sinatra that uses rack 2.x
42
+ gem 'sinatra', :git => 'https://github.com/sinatra/sinatra'
43
+
44
+ gem 'database_cleaner'
45
+ gem 'codacy-coverage'
46
+ gem 'delayed_job', '4.1.8.beta1', :require => false
47
+ gem 'generator_spec'
48
+ gem 'girl_friday', '>= 0.11.1'
49
+ gem 'redis'
50
+ gem 'resque'
51
+ gem 'simplecov'
52
+
53
+ unless is_jruby
54
+ # JRuby doesn't support fork, which is required for this test helper.
55
+ gem 'rspec-command'
56
+ end
57
+
58
+ gem 'mime-types'
59
+
60
+ gem 'webmock', :require => false
61
+
62
+ gem 'aws-sdk-sqs'
63
+ gem 'shoryuken'
64
+
65
+ gem 'capistrano', :require => false
66
+
67
+ gemspec :path => '../'
@@ -39,7 +39,7 @@ module Rails
39
39
  end
40
40
 
41
41
  def eval_runner
42
- if Rails.version >= '5.0.0'
42
+ if Rails.version >= '5.1.0'
43
43
  rails5_runner
44
44
  else
45
45
  legacy_runner
@@ -63,6 +63,9 @@ module Rollbar
63
63
  attr_reader :send_extra_frame_data
64
64
  attr_accessor :use_exception_level_filters_default
65
65
  attr_accessor :proxy
66
+ attr_accessor :raise_on_error
67
+ attr_accessor :transmit
68
+ attr_accessor :log_payload
66
69
 
67
70
  attr_reader :project_gem_paths
68
71
 
@@ -130,6 +133,9 @@ module Rollbar
130
133
  @project_gem_paths = []
131
134
  @use_exception_level_filters_default = false
132
135
  @proxy = nil
136
+ @raise_on_error = false
137
+ @transmit = true
138
+ @log_payload = false
133
139
  @collect_user_ip = true
134
140
  @anonymize_user_ip = false
135
141
  @hooks = {
@@ -270,7 +276,11 @@ module Rollbar
270
276
  end
271
277
 
272
278
  def logger_level=(level)
273
- @logger_level = level.to_sym
279
+ @logger_level = if level
280
+ level.to_sym
281
+ else
282
+ level
283
+ end
274
284
  end
275
285
 
276
286
  def logger
data/lib/rollbar/item.rb CHANGED
@@ -106,25 +106,34 @@ module Rollbar
106
106
  # Ensure all keys are strings since we can receive the payload inline or
107
107
  # from an async handler job, which can be serialized.
108
108
  stringified_payload = Util::Hash.deep_stringify_keys(payload)
109
- result = Truncation.truncate(stringified_payload)
109
+ attempts = []
110
+ result = Truncation.truncate(stringified_payload, attempts)
110
111
 
111
112
  return result unless Truncation.truncate?(result)
112
113
 
113
- handle_too_large_payload(stringified_payload, result)
114
+ handle_too_large_payload(stringified_payload, result, attempts)
114
115
 
115
116
  nil
116
117
  end
117
118
 
118
- def handle_too_large_payload(stringified_payload, final_payload)
119
- original_size = Rollbar::JSON.dump(stringified_payload).bytesize
120
- final_size = final_payload.bytesize
119
+ def handle_too_large_payload(stringified_payload, final_payload, attempts)
121
120
  uuid = stringified_payload['data']['uuid']
122
121
  host = stringified_payload['data'].fetch('server', {})['host']
123
122
 
124
- notifier.send_failsafe("Could not send payload due to it being too large after truncating attempts. Original size: #{original_size} Final size: #{final_size}", nil, uuid, host)
123
+ notifier.send_failsafe(
124
+ too_large_payload_string(attempts),
125
+ nil,
126
+ uuid,
127
+ host
128
+ )
125
129
  logger.error("[Rollbar] Payload too large to be sent for UUID #{uuid}: #{Rollbar::JSON.dump(payload)}")
126
130
  end
127
131
 
132
+ def too_large_payload_string(attempts)
133
+ 'Could not send payload due to it being too large after truncating attempts. ' \
134
+ "Original size: #{attempts.first} Attempts: #{attempts.join(', ')} Final size: #{attempts.last}"
135
+ end
136
+
128
137
  def ignored?
129
138
  data = payload['data']
130
139
 
data/lib/rollbar/json.rb CHANGED
@@ -1,13 +1,5 @@
1
- require 'multi_json'
2
- require 'rollbar/json/oj'
3
- require 'rollbar/json/default'
4
1
  require 'rollbar/language_support'
5
2
 
6
- begin
7
- require 'oj'
8
- rescue LoadError
9
- end
10
-
11
3
  module Rollbar
12
4
  module JSON # :nodoc:
13
5
  extend self
@@ -15,54 +7,13 @@ module Rollbar
15
7
  attr_writer :options_module
16
8
 
17
9
  def dump(object)
18
- # `basic_socket` plugin addresses the following issue: https://github.com/rollbar/rollbar-gem/issues/845
19
10
  Rollbar.plugins.get('basic_socket').load_scoped!(true) do
20
- with_adapter { MultiJson.dump(object, adapter_options) }
11
+ ::JSON.generate(object)
21
12
  end
22
13
  end
23
14
 
24
15
  def load(string)
25
- with_adapter { MultiJson.load(string, adapter_options) }
26
- end
27
-
28
- def with_adapter(&block)
29
- MultiJson.with_adapter(detect_multi_json_adapter, &block)
30
- end
31
-
32
- def detect_multi_json_adapter
33
- options = {}
34
- options[:adapter] = :oj if defined?(::Oj)
35
-
36
- MultiJson.current_adapter(options)
37
- end
38
-
39
- def adapter_options
40
- options_module.options
41
- end
42
-
43
- def options_module
44
- @options_module ||= find_options_module
45
- end
46
-
47
- def find_options_module
48
- module_name = multi_json_adapter_module_name
49
-
50
- if LanguageSupport.const_defined?(Rollbar::JSON, module_name, false)
51
- LanguageSupport.const_get(Rollbar::JSON, module_name, false)
52
- else
53
- Default
54
- end
55
- end
56
-
57
- # MultiJson adapters have this name structure:
58
- # "MultiJson::Adapters::{AdapterModule}"
59
- #
60
- # Ex: MultiJson::Adapters::Oj
61
- # Ex: MultiJson::Adapters::JsonGem
62
- #
63
- # In this method we just get the last module name.
64
- def multi_json_adapter_module_name
65
- detect_multi_json_adapter.name[/^MultiJson::Adapters::(.*)$/, 1]
16
+ ::JSON.parse(string)
66
17
  end
67
18
  end
68
19
  end
@@ -3,27 +3,11 @@ module Rollbar
3
3
  module_function
4
4
 
5
5
  def const_defined?(mod, target, inherit = true)
6
- if ruby_18?
7
- mod.const_defined?(target)
8
- else
9
- mod.const_defined?(target, inherit)
10
- end
6
+ mod.const_defined?(target, inherit)
11
7
  end
12
8
 
13
9
  def const_get(mod, target, inherit = true)
14
- if ruby_18?
15
- mod.const_get(target)
16
- else
17
- mod.const_get(target, inherit)
18
- end
19
- end
20
-
21
- def can_scrub_url?
22
- !version?('1.8')
23
- end
24
-
25
- def ruby_18?
26
- version?('1.8')
10
+ mod.const_get(target, inherit)
27
11
  end
28
12
 
29
13
  def ruby_19?
@@ -37,7 +21,7 @@ module Rollbar
37
21
  end
38
22
 
39
23
  def timeout_exceptions
40
- return [] if ruby_18? || ruby_19?
24
+ return [] if ruby_19?
41
25
 
42
26
  [Net::ReadTimeout, Net::OpenTimeout]
43
27
  end
@@ -36,7 +36,11 @@ module Rollbar
36
36
  def acceptable_levels
37
37
  @acceptable_levels ||= begin
38
38
  levels = [:debug, :info, :warn, :error]
39
- levels[levels.find_index(Rollbar.configuration.logger_level)..-1]
39
+ if Rollbar.configuration.logger_level
40
+ levels[levels.find_index(Rollbar.configuration.logger_level)..-1]
41
+ else
42
+ []
43
+ end
40
44
  end
41
45
  end
42
46
  end
@@ -147,13 +147,19 @@ module Rollbar
147
147
  level = lookup_exception_level(level, exception,
148
148
  use_exception_level_filters)
149
149
 
150
- begin
151
- report(level, message, exception, extra, context)
152
- rescue StandardError, SystemStackError => e
153
- report_internal_error(e)
150
+ ret = report_with_rescue(level, message, exception, extra, context)
154
151
 
155
- 'error'
156
- end
152
+ raise(exception) if configuration.raise_on_error && exception
153
+
154
+ ret
155
+ end
156
+
157
+ def report_with_rescue(level, message, exception, extra, context)
158
+ report(level, message, exception, extra, context)
159
+ rescue StandardError, SystemStackError => e
160
+ report_internal_error(e)
161
+
162
+ 'error'
157
163
  end
158
164
 
159
165
  # See log() above
@@ -429,15 +435,24 @@ module Rollbar
429
435
 
430
436
  return 'ignored' if item.ignored?
431
437
 
432
- schedule_item(item)
438
+ schedule_item(item) if configuration.transmit
439
+
440
+ log_and_return_item_data(item)
441
+ end
433
442
 
443
+ def log_and_return_item_data(item)
434
444
  data = item['data']
435
445
  log_instance_link(data)
436
446
  Rollbar.last_report = data
447
+ log_data(data) if configuration.log_payload
437
448
 
438
449
  data
439
450
  end
440
451
 
452
+ def log_data(data)
453
+ log_info "[Rollbar] Data: #{data}"
454
+ end
455
+
441
456
  # Reports an internal error in the Rollbar library. This will be reported within the configured
442
457
  # Rollbar project. We'll first attempt to provide a report including the exception traceback.
443
458
  # If that fails, we'll fall back to a more static failsafe response.
@@ -542,8 +557,6 @@ module Rollbar
542
557
 
543
558
  if uri.scheme == 'https'
544
559
  http.use_ssl = true
545
- # This is needed to have 1.8.7 passing tests
546
- http.ca_file = ENV['ROLLBAR_SSL_CERT_FILE'] if ENV.key?('ROLLBAR_SSL_CERT_FILE')
547
560
  http.verify_mode = ssl_verify_mode
548
561
  end
549
562
 
@@ -624,7 +637,7 @@ module Rollbar
624
637
  end
625
638
 
626
639
  def skip_retries?
627
- Rollbar::LanguageSupport.ruby_18? || Rollbar::LanguageSupport.ruby_19?
640
+ Rollbar::LanguageSupport.ruby_19?
628
641
  end
629
642
 
630
643
  def handle_response(response)