Class: Rollbar::Truncation::RemoveAnyKeyStrategy
- Inherits:
-
Object
- Object
- Rollbar::Truncation::RemoveAnyKeyStrategy
show all
- Includes:
- Mixin
- Defined in:
- lib/rollbar/truncation/remove_any_key_strategy.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Mixin
#dump, #select_frames, #truncate?
Constructor Details
Returns a new instance of RemoveAnyKeyStrategy.
14
15
16
17
18
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 14
def initialize(payload)
@payload = payload
@data = payload['data']
@extracted_title = (data['body']) if data['body']
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
8
9
10
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 8
def data
@data
end
|
Returns the value of attribute extracted_title.
8
9
10
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 8
def
@extracted_title
end
|
#payload ⇒ Object
Returns the value of attribute payload.
8
9
10
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 8
def payload
@payload
end
|
#sizes ⇒ Object
Returns the value of attribute sizes.
8
9
10
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 8
def sizes
@sizes
end
|
Class Method Details
.call(payload) ⇒ Object
10
11
12
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 10
def self.call(payload)
new(payload).call
end
|
Instance Method Details
#call ⇒ Object
20
21
22
23
24
25
26
27
28
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 20
def call
remove_unknown_root_keys
json_payload = remove_oversized_data_keys
return json_payload if json_payload
dump(payload)
end
|
#data_keys ⇒ Object
106
107
108
109
110
111
112
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 106
def data_keys
@data_keys ||= {}.tap do |hash|
data.keys.reject { |key| skip_keys.include?(key) }.each do |key|
set_key_size(key, hash)
end
end
end
|
91
92
93
94
95
96
97
98
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 91
def (body)
return body['message']['body'] if body['message'] && body['message']['body']
return (body['trace']) if body['trace']
return unless body['trace_chain'] && body['trace_chain'][0]
(body['trace_chain'][0])
end
|
100
101
102
103
104
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 100
def (trace)
exception = trace['exception']
"#{exception['class']}: #{exception['message']}"
end
|
#message_key ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 82
def message_key
{
'message' => {
'body' => 'Payload keys removed due to oversized payload. See diagnostic key'
}
}
end
|
#remove_key_and_return_payload(key) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 48
def remove_key_and_return_payload(key)
size = data_keys[key]
data.delete(key)
replace_message_body if key == 'body'
truncation_key[key] = "key removed, size: #{size} bytes"
dump(payload)
end
|
#remove_oversized_data_keys ⇒ Object
38
39
40
41
42
43
44
45
46
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 38
def remove_oversized_data_keys
data_keys.keys.sort { |a, b| data_keys[b] <=> data_keys[a] }.each do |key|
json_payload = remove_key_and_return_payload(key)
return json_payload unless truncate?(json_payload)
end
false
end
|
#remove_unknown_root_keys ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 30
def remove_unknown_root_keys
payload.keys.reject { |key| root_keys.include?(key) }.each do |key|
truncation_key['root'] ||= {}
size = dump(payload.delete(key)).bytesize
truncation_key['root'][key] = "unknown root key removed, size: #{size} bytes"
end
end
|
#replace_message_body ⇒ Object
60
61
62
63
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 60
def replace_message_body
data['body'] = message_key
data['title'] ||= if
end
|
#root_keys ⇒ Object
72
73
74
75
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 72
def root_keys
%w[access_token data]
end
|
#set_key_size(key, hash) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 114
def set_key_size(key, hash)
size = dump(data[key]).bytesize
hash[key] = size
rescue ::JSON::GeneratorError
hash[key] = 0
truncation_key['non_json_keys'] ||= {}
truncation_key['non_json_keys'][key] = data[key].class
end
|
#skip_keys ⇒ Object
77
78
79
80
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 77
def skip_keys
%w[notifier uuid title platform language framework level]
end
|
#truncation_key ⇒ Object
65
66
67
68
69
70
|
# File 'lib/rollbar/truncation/remove_any_key_strategy.rb', line 65
def truncation_key
@truncation_key ||=
(data['notifier']['diagnostic'] ||= {}) &&
(data['notifier']['diagnostic']['truncation'] ||= {})
end
|