getaround_utils 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 391634ba2c0e6d1c3fe81bbdaf24519a84dfaa61fa093b8cb5ef10b3b47445a1
4
- data.tar.gz: 0733525cd736128b202d0c6e8e87bb724685a09a8349ddb6fcdaccd8d10e6bee
3
+ metadata.gz: 6caee3209d10665822566c7ccc2d6b336c8132b72106aacda7db87a317a0f9f7
4
+ data.tar.gz: 241deaa2c3b3d37bb21bade62b517b54bee6fc62910113f2f40209862230d80c
5
5
  SHA512:
6
- metadata.gz: 9e1b37388a0f05c21337941a8badddbc4e0411c61bceb9e326d9e0c99d16459c7df9868d4e2b6a2dda566f08ff19ae56f939f33198cbd929165f7fab3086d2d1
7
- data.tar.gz: '095c102942a20a9fc4f9ec0ea445a560ced7b34bf9dab794e151c273b0b6845a84d888a7cb12a6542e37bfd5d26b675214769bdc82fe42adb9306c507cdbf1f2'
6
+ metadata.gz: c19cb3921b428f3cd7f5d885edb7eb2214fae0c07449f8a25e0a2225c6961408960d641f7a702b686cbf453476e4eea90e558f18ce0310af19ff49874f57ea17
7
+ data.tar.gz: 25230181f5c735e08c60384e5fd734969b4a703df25a2cf995f7582131a0e6b182e5d091e1bd5ab6d741f3b4008df09cb9d2c220e3ecaf5ab308ee913ca56eb0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- getaround_utils (0.1.8)
4
+ getaround_utils (0.1.9)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -65,6 +65,7 @@ GEM
65
65
  builder (3.2.3)
66
66
  coderay (1.1.2)
67
67
  concurrent-ruby (1.1.5)
68
+ connection_pool (2.2.2)
68
69
  crass (1.0.5)
69
70
  diff-lcs (1.3)
70
71
  erubi (1.9.0)
@@ -103,6 +104,8 @@ GEM
103
104
  coderay (~> 1.1.0)
104
105
  method_source (~> 0.9.0)
105
106
  rack (2.0.7)
107
+ rack-protection (2.0.7)
108
+ rack
106
109
  rack-test (1.1.0)
107
110
  rack (>= 1.0, < 3)
108
111
  rails (6.0.0)
@@ -133,6 +136,7 @@ GEM
133
136
  thor (>= 0.20.3, < 2.0)
134
137
  rainbow (3.0.0)
135
138
  rake (10.5.0)
139
+ redis (4.1.3)
136
140
  relaxed-rubocop (2.4)
137
141
  request_store (1.4.1)
138
142
  rack (>= 1.4)
@@ -167,6 +171,11 @@ GEM
167
171
  rubocop-rspec (1.36.0)
168
172
  rubocop (>= 0.68.1)
169
173
  ruby-progressbar (1.10.1)
174
+ sidekiq (6.0.3)
175
+ connection_pool (>= 2.2.2)
176
+ rack (>= 2.0.0)
177
+ rack-protection (>= 2.0.0)
178
+ redis (>= 4.1.0)
170
179
  sprockets (4.0.0)
171
180
  concurrent-ruby (~> 1.0)
172
181
  rack (> 1, < 3)
@@ -199,6 +208,7 @@ DEPENDENCIES
199
208
  rspec-rails (~> 3.9)
200
209
  rubocop (~> 0.75, >= 0.75.0)
201
210
  rubocop-rspec (~> 1.36, >= 0.36.0)
211
+ sidekiq (~> 6.0)
202
212
 
203
213
  BUNDLED WITH
204
214
  2.0.2
data/README.md CHANGED
@@ -52,6 +52,19 @@ GetaroundUtils::Patches::KeyValueLogTags.enable
52
52
 
53
53
  For more details, [read the spec](spec/getaround_utils/patches/key_value_log_tags_spec.rb)
54
54
 
55
+
56
+ ### GetaroundUtils::Patches::KeyValueSidekiqExceptions
57
+
58
+ Enables parse-able exception logging from Sidekiq
59
+ ```
60
+ # config/application.rb
61
+ require 'getaround_utils/patches/key_value_sidekiq_exceptions'
62
+ GetaroundUtils::Patches::KeyValueSidekiqExceptions.enable
63
+ ```
64
+
65
+ For more details, [read the spec](spec/getaround_utils/patches/key_value_sidekiq_exceptions_spec.rb)
66
+
67
+
55
68
  ## Misc
56
69
 
57
70
  ### GetaroundUtils::LogFormatters::DeepKeyValue
@@ -24,4 +24,5 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency 'rspec-rails', '~> 3.9'
25
25
  gem.add_development_dependency 'rubocop', '~> 0.75', '>= 0.75.0'
26
26
  gem.add_development_dependency 'rubocop-rspec', '~> 1.36', '>= 0.36.0'
27
+ gem.add_development_dependency 'sidekiq', '~> 6.0'
27
28
  end
@@ -10,51 +10,41 @@ require 'getaround_utils/utils/deep_key_value_serializer'
10
10
  # It will attempt to serialize message it is a string otherwise adding it as message=value
11
11
 
12
12
  class GetaroundUtils::LogFormatters::DeepKeyValue < GetaroundUtils::Utils::DeepKeyValueSerializer
13
- def call(severity, _datetime, appname, message)
14
- payload = { severity: severity, appname: appname }
13
+ def normalize(message)
15
14
  if message.is_a?(Hash)
16
- "#{serialize(payload.merge(message).compact)}\n"
15
+ serialize(message.compact)
16
+ elsif message.is_a?(String) && message.match(/^[^ =]+=/)
17
+ message
17
18
  else
18
- "#{serialize(payload.compact)} #{message}\n"
19
+ serialize(message: message.to_s)
19
20
  end
20
21
  end
21
22
 
23
+ def call(severity, _datetime, appname, message)
24
+ payload = { severity: severity, appname: appname }
25
+ "#{normalize(payload)} #{normalize(message)}\n"
26
+ end
27
+
22
28
  module Lograge
23
- def call(data)
24
- data.compact! if data.is_a?(Hash)
25
- serialize(data)
29
+ def call(message)
30
+ message = message.compact if message.is_a?(Hash)
31
+ serialize(message)
26
32
  end
27
33
  end
28
34
 
29
- ##
30
- # Return a lograge-style LogFormatter
31
- #
32
- # This formatter will only take one argument and serialize it
33
-
34
35
  def self.for_lograge
35
36
  new.extend(Lograge)
36
37
  end
37
38
 
38
39
  module Sidekiq
39
40
  def call(severity, _datetime, appname, message)
40
- payload = {}
41
- payload[:sidekiq] = Thread.current[:sidekiq_context] || {}
42
- payload[:sidekiq][:tid] = Thread.current['sidekiq_tid']
43
- message = if message.is_a?(Hash)
44
- message.merge(payload.compact)
45
- else
46
- "#{serialize(payload.compact)} #{message}"
47
- end
48
- super
41
+ payload = { severity: severity, appname: appname }
42
+ sidekiq = { sidekiq: Thread.current[:sidekiq_context] || {} }
43
+ sidekiq[:sidekiq][:tid] = Thread.current['sidekiq_tid']
44
+ "#{normalize(payload)} #{normalize(message)} #{normalize(sidekiq)}\n"
49
45
  end
50
46
  end
51
47
 
52
- ##
53
- # Return a sidekiq-style LogFormatter
54
- #
55
- # This formatter replicates the default Sidekiq LogFormatter behavior of merging context
56
- # values from the current Thread's store
57
-
58
48
  def self.for_sidekiq
59
49
  new.extend(Sidekiq)
60
50
  end
@@ -1,3 +1,4 @@
1
1
  module GetaroundUtils::Patches
2
2
  autoload :KeyValueLogTags, 'getaround_utils/patches/key_value_log_tags'
3
+ autoload :KeyValueSidekiqExceptions, 'getaround_utils/patches/key_value_sidekiq_exceptions'
3
4
  end
@@ -1,4 +1,3 @@
1
- require 'rails/railtie'
2
1
  require 'getaround_utils/utils/deep_key_value_serializer'
3
2
 
4
3
  module GetaroundUtils; end
@@ -0,0 +1,26 @@
1
+ require 'sidekiq/exception_handler'
2
+ require 'getaround_utils/utils/deep_key_value_serializer'
3
+
4
+ module GetaroundUtils; end
5
+ module GetaroundUtils::Patches; end
6
+
7
+ class GetaroundUtils::Patches::KeyValueSidekiqExceptions
8
+ module ExceptionHandlerLogger
9
+ def kv_formatter
10
+ @kv_formatter ||= GetaroundUtils::Utils::DeepKeyValueSerializer.new
11
+ end
12
+
13
+ def call(exception, ctx)
14
+ payload = {}
15
+ payload[:exception] = exception&.class&.name
16
+ payload[:sidekiq] = ctx
17
+ payload[:message] = exception&.message
18
+ payload[:backtrace] = exception&.backtrace&.join("\n")
19
+ Sidekiq.logger.warn(kv_formatter.serialize(payload.compact))
20
+ end
21
+ end
22
+
23
+ def self.enable
24
+ Sidekiq::ExceptionHandler::Logger.prepend ExceptionHandlerLogger
25
+ end
26
+ end
@@ -2,6 +2,11 @@ module GetaroundUtils; end
2
2
  module GetaroundUtils::Utils; end
3
3
 
4
4
  class GetaroundUtils::Utils::DeepKeyValueSerializer
5
+ def initialize(max_depth: 5, max_length: 512)
6
+ @max_depth = max_depth
7
+ @max_length = max_length
8
+ end
9
+
5
10
  def serialize(data)
6
11
  case data
7
12
  when Array
@@ -19,6 +24,10 @@ class GetaroundUtils::Utils::DeepKeyValueSerializer
19
24
 
20
25
  # https://stackoverflow.com/questions/48836464/how-to-flatten-a-hash-making-each-key-a-unique-value
21
26
  def flattify(value, result = {}, path = [])
27
+ if path.length > @max_depth
28
+ result[path.join(".")] = '"..."'
29
+ return result
30
+ end
22
31
  case value
23
32
  when Array
24
33
  value.each.with_index(0) do |v, i|
@@ -31,9 +40,14 @@ class GetaroundUtils::Utils::DeepKeyValueSerializer
31
40
  when Numeric
32
41
  result[path.join(".")] = value.to_s
33
42
  when String
34
- result[path.join(".")] = value =~ /^".*"$/ ? value : value.inspect
43
+ value = if value =~ /^".*"$/
44
+ value.length >= @max_length ? %{#{value[0...@max_length]} ..."} : value
45
+ else
46
+ value.length >= @max_length ? %{#{value[0...@max_length]} ...}.inspect : value.inspect
47
+ end
48
+ result[path.join(".")] = value
35
49
  else
36
- result[path.join(".")] = value.to_s.inspect
50
+ flattify(value.to_s, result, path)
37
51
  end
38
52
  result
39
53
  end
@@ -1,3 +1,3 @@
1
1
  module GetaroundUtils
2
- VERSION = '0.1.8'.freeze
2
+ VERSION = '0.1.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getaround_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drivy
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-15 00:00:00.000000000 Z
12
+ date: 2019-11-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -175,6 +175,20 @@ dependencies:
175
175
  - - "~>"
176
176
  - !ruby/object:Gem::Version
177
177
  version: '1.36'
178
+ - !ruby/object:Gem::Dependency
179
+ name: sidekiq
180
+ requirement: !ruby/object:Gem::Requirement
181
+ requirements:
182
+ - - "~>"
183
+ - !ruby/object:Gem::Version
184
+ version: '6.0'
185
+ type: :development
186
+ prerelease: false
187
+ version_requirements: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - "~>"
190
+ - !ruby/object:Gem::Version
191
+ version: '6.0'
178
192
  description: Shared base utility classes for Getaround Backend Applications.
179
193
  email:
180
194
  - oss@drivy.com
@@ -194,6 +208,7 @@ files:
194
208
  - lib/getaround_utils/mixins/loggable.rb
195
209
  - lib/getaround_utils/patches.rb
196
210
  - lib/getaround_utils/patches/key_value_log_tags.rb
211
+ - lib/getaround_utils/patches/key_value_sidekiq_exceptions.rb
197
212
  - lib/getaround_utils/railties/lograge.rb
198
213
  - lib/getaround_utils/utils.rb
199
214
  - lib/getaround_utils/utils/deep_key_value_serializer.rb