rollbar 2.20.1 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,6 @@ module Rollbar
14
14
 
15
15
  def call(options = {})
16
16
  url = options[:url]
17
- return url unless Rollbar::LanguageSupport.can_scrub_url?
18
17
 
19
18
  filter(url,
20
19
  build_regex(options[:scrub_fields]),
@@ -6,6 +6,7 @@ require 'rollbar/truncation/strings_strategy'
6
6
  require 'rollbar/truncation/min_body_strategy'
7
7
  require 'rollbar/truncation/remove_request_strategy'
8
8
  require 'rollbar/truncation/remove_extra_strategy'
9
+ require 'rollbar/truncation/remove_any_key_strategy'
9
10
 
10
11
  module Rollbar
11
12
  module Truncation
@@ -17,7 +18,8 @@ module Rollbar
17
18
  StringsStrategy,
18
19
  MinBodyStrategy,
19
20
  RemoveRequestStrategy,
20
- RemoveExtraStrategy].freeze
21
+ RemoveExtraStrategy,
22
+ RemoveAnyKeyStrategy].freeze
21
23
 
22
24
  def self.truncate(payload, attempts = [])
23
25
  result = nil
@@ -0,0 +1,123 @@
1
+ require 'rollbar/util'
2
+
3
+ module Rollbar
4
+ module Truncation
5
+ class RemoveAnyKeyStrategy
6
+ include ::Rollbar::Truncation::Mixin
7
+
8
+ attr_accessor :payload, :data, :sizes, :extracted_title
9
+
10
+ def self.call(payload)
11
+ new(payload).call
12
+ end
13
+
14
+ def initialize(payload)
15
+ @payload = payload
16
+ @data = payload['data']
17
+ @extracted_title = extract_title(data['body']) if data['body']
18
+ end
19
+
20
+ def call
21
+ remove_unknown_root_keys
22
+
23
+ json_payload = remove_oversized_data_keys
24
+
25
+ return json_payload if json_payload
26
+
27
+ dump(payload)
28
+ end
29
+
30
+ def remove_unknown_root_keys
31
+ payload.keys.reject { |key| root_keys.include?(key) }.each do |key|
32
+ truncation_key['root'] ||= {}
33
+ size = dump(payload.delete(key)).bytesize
34
+ truncation_key['root'][key] = "unknown root key removed, size: #{size} bytes"
35
+ end
36
+ end
37
+
38
+ def remove_oversized_data_keys
39
+ data_keys.keys.sort { |a, b| data_keys[b] <=> data_keys[a] }.each do |key|
40
+ json_payload = remove_key_and_return_payload(key)
41
+
42
+ return json_payload unless truncate?(json_payload)
43
+ end
44
+
45
+ false
46
+ end
47
+
48
+ def remove_key_and_return_payload(key)
49
+ size = data_keys[key]
50
+
51
+ data.delete(key)
52
+
53
+ replace_message_body if key == 'body'
54
+
55
+ truncation_key[key] = "key removed, size: #{size} bytes"
56
+
57
+ dump(payload)
58
+ end
59
+
60
+ def replace_message_body
61
+ data['body'] = message_key
62
+ data['title'] ||= extracted_title if extracted_title
63
+ end
64
+
65
+ def truncation_key
66
+ @truncation_key ||=
67
+ # initialize the diagnostic key for truncation
68
+ (data['notifier']['diagnostic'] ||= {}) &&
69
+ (data['notifier']['diagnostic']['truncation'] ||= {})
70
+ end
71
+
72
+ def root_keys
73
+ # Valid keys in root of payload
74
+ %w[access_token data]
75
+ end
76
+
77
+ def skip_keys
78
+ # Don't try to truncate these data keys
79
+ %w[notifier uuid title platform language framework level]
80
+ end
81
+
82
+ def message_key
83
+ # use this message if data.body gets removed
84
+ {
85
+ 'message' => {
86
+ 'body' => 'Payload keys removed due to oversized payload. See diagnostic key'
87
+ }
88
+ }
89
+ end
90
+
91
+ def extract_title(body)
92
+ return body['message']['body'] if body['message'] && body['message']['body']
93
+ return extract_title_from_trace(body['trace']) if body['trace']
94
+ return extract_title_from_trace(body['trace_chain'][0]) if body['trace_chain'] && body['trace_chain'][0]
95
+ end
96
+
97
+ def extract_title_from_trace(trace)
98
+ exception = trace['exception']
99
+
100
+ "#{exception['class']}: #{exception['message']}"
101
+ end
102
+
103
+ def data_keys
104
+ @data_keys ||= {}.tap do |hash|
105
+ data.keys.reject { |key| skip_keys.include?(key) }.each do |key|
106
+ set_key_size(key, hash)
107
+ end
108
+ end
109
+ end
110
+
111
+ def set_key_size(key, hash)
112
+ size = dump(data[key]).bytesize
113
+ hash[key] = size
114
+ rescue ::JSON::GeneratorError
115
+ hash[key] = 0 # don't try to truncate non JSON object
116
+
117
+ # Log it
118
+ truncation_key['non_json_keys'] ||= {}
119
+ truncation_key['non_json_keys'][key] = data[key].class
120
+ end
121
+ end
122
+ end
123
+ end
data/lib/rollbar/util.rb CHANGED
@@ -63,9 +63,9 @@ module Rollbar
63
63
 
64
64
  def self.clone_obj(obj)
65
65
  if obj.is_a?(::Hash)
66
- obj.clone
66
+ obj.dup
67
67
  elsif obj.is_a?(Array)
68
- obj.clone.clear
68
+ obj.dup.clear
69
69
  else
70
70
  obj
71
71
  end
@@ -5,6 +5,7 @@ module Rollbar
5
5
  return if seen[hash.object_id]
6
6
 
7
7
  seen[hash.object_id] = true
8
+ replace_seen_children(hash, seen)
8
9
 
9
10
  hash.reduce({}) do |h, (key, value)|
10
11
  h[key.to_s] = map_value(value, :deep_stringify_keys, seen)
@@ -22,12 +23,26 @@ module Rollbar
22
23
  thing
23
24
  else
24
25
  seen[thing.object_id] = true
26
+ replace_seen_children(thing, seen)
25
27
  thing.map { |v| map_value(v, meth, seen) }
26
28
  end
27
29
  else
28
30
  thing
29
31
  end
30
32
  end
33
+
34
+ def self.replace_seen_children(thing, seen)
35
+ case thing
36
+ when ::Hash
37
+ thing.keys.each do |key|
38
+ thing[key] = "removed circular reference: #{thing[key]}" if seen[thing[key].object_id]
39
+ end
40
+ when Array
41
+ thing.each_with_index do |_, i|
42
+ thing[i] = "removed circular reference: #{thing[i]}" if seen[thing[i].object_id]
43
+ end
44
+ end
45
+ end
31
46
  end
32
47
  end
33
48
  end
@@ -1,3 +1,3 @@
1
1
  module Rollbar
2
- VERSION = '2.20.1'.freeze
2
+ VERSION = '2.21.0'.freeze
3
3
  end
data/rollbar.gemspec CHANGED
@@ -18,8 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.required_ruby_version = '>= 1.9.3'
19
19
  gem.version = Rollbar::VERSION
20
20
 
21
- gem.add_runtime_dependency 'multi_json'
22
-
23
21
  if gem.respond_to?(:metadata)
24
22
  gem.metadata['changelog_uri'] = 'https://github.com/rollbar/rollbar-gem/releases'
25
23
  gem.metadata['source_code_uri'] = 'https://github.com/rollbar/rollbar-gem'
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rollbar
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.20.1
4
+ version: 2.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rollbar, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-05-30 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: multi_json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
11
+ date: 2019-07-12 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Easy and powerful exception tracking for Ruby
28
14
  email:
29
15
  - support@rollbar.com
@@ -59,7 +45,7 @@ files:
59
45
  - gemfiles/rails50.gemfile
60
46
  - gemfiles/rails51.gemfile
61
47
  - gemfiles/rails52.gemfile
62
- - gemfiles/ruby_1_8_and_1_9_2.gemfile
48
+ - gemfiles/rails60.gemfile
63
49
  - lib/generators/rollbar/rollbar_generator.rb
64
50
  - lib/generators/rollbar/templates/initializer.rb
65
51
  - lib/rails/rollbar_runner.rb
@@ -88,8 +74,6 @@ files:
88
74
  - lib/rollbar/item/locals.rb
89
75
  - lib/rollbar/js.rb
90
76
  - lib/rollbar/json.rb
91
- - lib/rollbar/json/default.rb
92
- - lib/rollbar/json/oj.rb
93
77
  - lib/rollbar/language_support.rb
94
78
  - lib/rollbar/lazy_store.rb
95
79
  - lib/rollbar/logger.rb
@@ -128,6 +112,7 @@ files:
128
112
  - lib/rollbar/rails.rb
129
113
  - lib/rollbar/rake_tasks.rb
130
114
  - lib/rollbar/request_data_extractor.rb
115
+ - lib/rollbar/rollbar_test.rb
131
116
  - lib/rollbar/scrubbers.rb
132
117
  - lib/rollbar/scrubbers/params.rb
133
118
  - lib/rollbar/scrubbers/url.rb
@@ -136,6 +121,7 @@ files:
136
121
  - lib/rollbar/truncation/min_body_strategy.rb
137
122
  - lib/rollbar/truncation/mixin.rb
138
123
  - lib/rollbar/truncation/raw_strategy.rb
124
+ - lib/rollbar/truncation/remove_any_key_strategy.rb
139
125
  - lib/rollbar/truncation/remove_extra_strategy.rb
140
126
  - lib/rollbar/truncation/remove_request_strategy.rb
141
127
  - lib/rollbar/truncation/strings_strategy.rb
@@ -1,51 +0,0 @@
1
- require 'rubygems/version'
2
-
3
- source 'https://rubygems.org'
4
-
5
- is_jruby = defined?(JRUBY_VERSION) || (defined?(RUBY_ENGINE) && 'jruby' == RUBY_ENGINE)
6
-
7
- gem 'appraisal', '= 1.0.2'
8
- gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
9
- gem 'hitimes', '< 1.2.2'
10
- gem 'jruby-openssl', :platform => :jruby
11
- gem 'rails', '3.0.20'
12
- gem 'rake', '< 11'
13
- gem 'rspec-rails', '>= 2.14.0'
14
- gem 'sqlite3', '< 1.4.0', :platform => [:ruby, :mswin, :mingw]
15
-
16
- gem 'oj', '~> 2.12.14' unless is_jruby
17
- if RUBY_VERSION > '1.8.7' && RUBY_VERSION < '2.2.2'
18
- gem 'sidekiq', '>= 2.13.0', '< 5.0'
19
- end
20
-
21
- platforms :rbx do
22
- gem 'minitest'
23
- gem 'racc'
24
- gem 'rubinius-developer_tools'
25
- gem 'rubysl', '~> 2.0' unless RUBY_VERSION.start_with?('1')
26
- end
27
-
28
- if RUBY_VERSION.start_with?('1.9')
29
- gem 'celluloid', '< 0.17.0'
30
- gem 'sucker_punch', '~> 1.0'
31
- elsif RUBY_VERSION.start_with?('2')
32
- gem 'sucker_punch', '~> 2.0'
33
- end
34
-
35
- gem 'database_cleaner', '~> 1.0.0'
36
- gem 'delayed_job', '4.1.3', :require => false
37
- gem 'genspec', '= 0.2.8'
38
- gem 'girl_friday', '>= 0.11.1'
39
- gem 'redis', '< 3.3.5'
40
- gem 'resque', '< 2.0.0'
41
- gem 'sinatra'
42
-
43
- ruby_version = RUBY_VERSION.dup
44
-
45
- if Gem::Version.new(ruby_version) < Gem::Version.new('2.0')
46
- gem 'mime-types', '< 3.0'
47
- end
48
-
49
- gem 'capistrano', '<= 3.4.1', :require => false
50
-
51
- gemspec :path => '../'
@@ -1,11 +0,0 @@
1
- module Rollbar
2
- module JSON
3
- module Default
4
- module_function
5
-
6
- def options
7
- {}
8
- end
9
- end
10
- end
11
- end
@@ -1,16 +0,0 @@
1
- module Rollbar
2
- module JSON
3
- module Oj
4
- module_function
5
-
6
- def options
7
- {
8
- :mode => :compat,
9
- :use_to_json => false,
10
- :symbol_keys => false,
11
- :circular => false
12
- }
13
- end
14
- end
15
- end
16
- end