getaround_utils 0.2.7 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/getaround_utils.gemspec +1 -1
- data/lib/getaround_utils/mixins/loggable.rb +5 -15
- data/lib/getaround_utils/ougai/json_formatter.rb +1 -0
- data/lib/getaround_utils/railties/lograge.rb +13 -3
- data/lib/getaround_utils/railties/ougai.rb +17 -9
- data/lib/getaround_utils/utils.rb +0 -3
- data/lib/getaround_utils/version.rb +1 -1
- metadata +4 -7
- data/lib/getaround_utils/utils/async_queue.rb +0 -49
- data/lib/getaround_utils/utils/captur_reporter.rb +0 -32
- data/lib/getaround_utils/utils/http_reporter.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5fb2e983311d51793f19b40c1650fa338bac50c97570af7c8155ed9d0d3e604
|
4
|
+
data.tar.gz: cca129082b35867980ad77bba62bf50cc4b8915ee202c41e861f66cc943d069d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '097c3b06d8f9da62c1d831474d69dcff2950a4920fdff0a9a75a9e8c42c14466f63ed399ef27fe9c8344967445dcfd5251840c48b69dd1038d2769e6d560832b'
|
7
|
+
data.tar.gz: edd536e5ffad5d30980d1de0f3b5a0d5ebf42da09c0f5d7e58651af541202292c70501a1992a03849676811c0db7c74116bd75306a766a086859b0e738752571
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
getaround_utils (0.2.
|
4
|
+
getaround_utils (0.2.14)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -103,7 +103,7 @@ GEM
|
|
103
103
|
minitest (5.13.0)
|
104
104
|
multipart-post (2.1.1)
|
105
105
|
nio4r (2.5.2)
|
106
|
-
nokogiri (1.10.
|
106
|
+
nokogiri (1.10.10)
|
107
107
|
mini_portile2 (~> 2.4.0)
|
108
108
|
oj (3.10.14)
|
109
109
|
ougai (1.8.5)
|
@@ -115,7 +115,7 @@ GEM
|
|
115
115
|
coderay (~> 1.1.0)
|
116
116
|
method_source (~> 0.9.0)
|
117
117
|
public_suffix (4.0.2)
|
118
|
-
rack (2.
|
118
|
+
rack (2.2.3)
|
119
119
|
rack-protection (2.0.7)
|
120
120
|
rack
|
121
121
|
rack-test (1.1.0)
|
@@ -147,7 +147,7 @@ GEM
|
|
147
147
|
rake (>= 0.8.7)
|
148
148
|
thor (>= 0.20.3, < 2.0)
|
149
149
|
rainbow (3.0.0)
|
150
|
-
rake (
|
150
|
+
rake (12.3.3)
|
151
151
|
redis (4.1.3)
|
152
152
|
relaxed-rubocop (2.4)
|
153
153
|
request_store (1.4.1)
|
@@ -209,7 +209,7 @@ GEM
|
|
209
209
|
hashdiff (>= 0.4.0, < 2.0.0)
|
210
210
|
websocket-driver (0.7.1)
|
211
211
|
websocket-extensions (>= 0.1.0)
|
212
|
-
websocket-extensions (0.1.
|
212
|
+
websocket-extensions (0.1.5)
|
213
213
|
zeitwerk (2.2.1)
|
214
214
|
|
215
215
|
PLATFORMS
|
@@ -224,7 +224,7 @@ DEPENDENCIES
|
|
224
224
|
ougai (~> 1.8)
|
225
225
|
pry (~> 0.12.2)
|
226
226
|
rails (~> 6.0)
|
227
|
-
rake (~>
|
227
|
+
rake (~> 12.3)
|
228
228
|
request_store_rails (~> 2.0)
|
229
229
|
rspec (~> 3.9, >= 3.9.0)
|
230
230
|
rspec-rails (~> 3.9)
|
data/getaround_utils.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.add_development_dependency 'lograge', '~> 0.11.2'
|
20
20
|
gem.add_development_dependency 'pry', '~> 0.12.2'
|
21
21
|
gem.add_development_dependency 'rails', '~> 6.0'
|
22
|
-
gem.add_development_dependency "rake", "~>
|
22
|
+
gem.add_development_dependency "rake", "~> 12.3"
|
23
23
|
gem.add_development_dependency 'rspec', '~> 3.9', '>= 3.9.0'
|
24
24
|
gem.add_development_dependency 'rspec-rails', '~> 3.9'
|
25
25
|
gem.add_development_dependency 'rubocop', '~> 0.75', '>= 0.75.0'
|
@@ -14,26 +14,16 @@ module GetaroundUtils::Mixins::Loggable
|
|
14
14
|
append_infos_to_loggable(payload)
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
18
|
-
@
|
19
|
-
logger
|
20
|
-
elsif defined?(Rails)
|
21
|
-
Rails.logger
|
22
|
-
else
|
23
|
-
Logger.new(STDOUT)
|
24
|
-
end
|
17
|
+
def loggable_logger_fallback
|
18
|
+
@loggable_logger_fallback ||= Logger.new(STDOUT)
|
25
19
|
end
|
26
20
|
|
27
|
-
def
|
28
|
-
|
29
|
-
:warn,
|
30
|
-
"Deprecated usage of GetaroundUtils::Mixins::Loggable#loggable(*args). Please use GetaroundUtils::Mixins::Loggable#loggable_log(*args) instead"
|
31
|
-
)
|
32
|
-
loggable_log(severity, message, payload)
|
21
|
+
def loggable_logger
|
22
|
+
(logger if respond_to?(:logger)) || (Rails.logger if defined?(Rails)) || loggable_logger_fallback
|
33
23
|
end
|
34
24
|
|
35
25
|
def loggable_log(severity, message, payload = {})
|
36
26
|
base_append_infos_to_loggable(payload)
|
37
|
-
|
27
|
+
loggable_logger.send(severity.to_sym, msg: message, **payload)
|
38
28
|
end
|
39
29
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rails/railtie'
|
2
4
|
require 'lograge'
|
3
5
|
|
@@ -8,13 +10,12 @@ class GetaroundUtils::Railties::Lograge < Rails::Railtie
|
|
8
10
|
module LogrageActionController
|
9
11
|
def append_info_to_payload(payload)
|
10
12
|
super
|
11
|
-
payload[:lograge]
|
13
|
+
payload[:lograge] = {}
|
12
14
|
payload[:lograge][:host] = request.host
|
13
15
|
payload[:lograge][:params] = request.filtered_parameters.except(:action, :controller)
|
14
16
|
payload[:lograge][:remote_ip] = request.remote_ip
|
15
17
|
payload[:lograge][:user_agent] = request.user_agent
|
16
18
|
payload[:lograge][:referer] = request.referer
|
17
|
-
payload[:lograge][:controller_action] = "#{params[:controller]}##{params[:action]}" if defined?(params)
|
18
19
|
payload[:lograge][:session_id] = session.is_a?(Hash) ? session[:id] : session.id if defined?(session)
|
19
20
|
payload[:lograge][:user_id] = current_user&.id if defined?(current_user)
|
20
21
|
end
|
@@ -24,6 +25,15 @@ class GetaroundUtils::Railties::Lograge < Rails::Railtie
|
|
24
25
|
ActionController::Base.prepend LogrageActionController
|
25
26
|
end
|
26
27
|
|
28
|
+
HTTP_PARAMS = [:method, :path, :host, :remote_ip,
|
29
|
+
:status, :duration, :location,
|
30
|
+
:user_agent, :referer].freeze
|
31
|
+
|
27
32
|
config.lograge.enabled = true
|
28
|
-
config.lograge.custom_options = ->(event) {
|
33
|
+
config.lograge.custom_options = ->(event) {
|
34
|
+
event.payload[:lograge]
|
35
|
+
}
|
36
|
+
config.lograge.before_format = ->(data, _) {
|
37
|
+
data.except(*HTTP_PARAMS).merge(http: data.slice(*HTTP_PARAMS))
|
38
|
+
}
|
29
39
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'getaround_utils/ougai/
|
3
|
+
require 'getaround_utils/ougai/json_formatter'
|
4
4
|
require 'request_store'
|
5
5
|
require 'rails/railtie'
|
6
6
|
require 'ougai'
|
@@ -19,9 +19,13 @@ end
|
|
19
19
|
# https://github.com/tilfin/ougai/wiki/Use-as-Rails-logger#with-activesupporttaggedlogging
|
20
20
|
module OugaiTaggedLoggingFormatter
|
21
21
|
def call(severity, time, progname, data)
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
if is_a?(Ougai::Formatters::Base)
|
23
|
+
data = { msg: data.to_s } unless data.is_a?(Hash)
|
24
|
+
data[:tags] = current_tags if current_tags.any?
|
25
|
+
_call(severity, time, progname, data)
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
@@ -34,7 +38,7 @@ class OugaiRequestStoreMiddleware
|
|
34
38
|
end
|
35
39
|
|
36
40
|
def call(env)
|
37
|
-
RequestStore.store[:ougai] = { request_id: env['action_dispatch.request_id'] }
|
41
|
+
RequestStore.store[:ougai] = { http: { request_id: env['action_dispatch.request_id'] } }
|
38
42
|
@app.call(env)
|
39
43
|
end
|
40
44
|
end
|
@@ -42,10 +46,10 @@ end
|
|
42
46
|
class GetaroundUtils::Railties::Ougai < Rails::Railtie
|
43
47
|
config.ougai_logger = OugaiRailsLogger.new(STDOUT)
|
44
48
|
config.ougai_logger.after_initialize if Rails::VERSION::MAJOR < 6
|
45
|
-
config.ougai_logger.formatter = GetaroundUtils::Ougai::
|
49
|
+
config.ougai_logger.formatter = GetaroundUtils::Ougai::JsonFormatter.new
|
46
50
|
config.ougai_logger.before_log = lambda do |data|
|
47
51
|
request_store = RequestStore.store[:ougai] || {}
|
48
|
-
data.
|
52
|
+
data.deep_merge!(request_store) if request_store&.any?
|
49
53
|
|
50
54
|
sidekiq_context = Thread.current[:sidekiq_context] || {}
|
51
55
|
data.merge!(sidekiq: sidekiq_context) if sidekiq_context&.any?
|
@@ -77,9 +81,13 @@ class GetaroundUtils::Railties::Ougai < Rails::Railtie
|
|
77
81
|
Sidekiq.logger = config.ougai_logger
|
78
82
|
|
79
83
|
Sidekiq.configure_server do |config|
|
80
|
-
config.error_handlers.shift
|
84
|
+
original_handler = config.error_handlers.shift
|
81
85
|
config.error_handlers << lambda do |ex, ctx|
|
82
|
-
Sidekiq.logger.
|
86
|
+
if Sidekiq.logger.is_a?(Ougai::Logger)
|
87
|
+
Sidekiq.logger.warn(ex, job: ctx[:job])
|
88
|
+
else
|
89
|
+
original_handler.call(ex, ctx)
|
90
|
+
end
|
83
91
|
end
|
84
92
|
end
|
85
93
|
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.2.
|
4
|
+
version: 0.2.14
|
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: 2020-
|
12
|
+
date: 2020-11-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -93,14 +93,14 @@ dependencies:
|
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '12.3'
|
97
97
|
type: :development
|
98
98
|
prerelease: false
|
99
99
|
version_requirements: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '12.3'
|
104
104
|
- !ruby/object:Gem::Dependency
|
105
105
|
name: rspec
|
106
106
|
requirement: !ruby/object:Gem::Requirement
|
@@ -211,10 +211,7 @@ files:
|
|
211
211
|
- lib/getaround_utils/railties/lograge.rb
|
212
212
|
- lib/getaround_utils/railties/ougai.rb
|
213
213
|
- lib/getaround_utils/utils.rb
|
214
|
-
- lib/getaround_utils/utils/async_queue.rb
|
215
|
-
- lib/getaround_utils/utils/captur_reporter.rb
|
216
214
|
- lib/getaround_utils/utils/deep_key_value.rb
|
217
|
-
- lib/getaround_utils/utils/http_reporter.rb
|
218
215
|
- lib/getaround_utils/version.rb
|
219
216
|
homepage: https://github.com/drivy
|
220
217
|
licenses:
|
@@ -1,49 +0,0 @@
|
|
1
|
-
module GetaroundUtils; end
|
2
|
-
module GetaroundUtils::Utils; end
|
3
|
-
|
4
|
-
class GetaroundUtils::Utils::AsyncQueue
|
5
|
-
include GetaroundUtils::Mixins::Loggable
|
6
|
-
|
7
|
-
MAX_QUEUE_SIZE = 1000
|
8
|
-
BUFFER_SIZE = 50
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@queue = []
|
12
|
-
@mutex = Mutex.new
|
13
|
-
@closed = false
|
14
|
-
@worker = Thread.new(&method(:thread_run))
|
15
|
-
at_exit { terminate }
|
16
|
-
end
|
17
|
-
|
18
|
-
def perform
|
19
|
-
raise NotImplementedError
|
20
|
-
end
|
21
|
-
|
22
|
-
def push(payload)
|
23
|
-
@mutex.synchronize do
|
24
|
-
if @queue.size >= MAX_QUEUE_SIZE
|
25
|
-
loggable_log(:error, 'queue overflow')
|
26
|
-
else
|
27
|
-
@queue.push(payload)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def thread_run
|
33
|
-
loop do
|
34
|
-
buffer = @mutex.synchronize { @queue.shift(BUFFER_SIZE) }
|
35
|
-
loggable_log(:debug, 'thread_run', buffer_size: buffer.size)
|
36
|
-
return if @closed && buffer.empty?
|
37
|
-
|
38
|
-
perform(buffer) unless buffer.empty?
|
39
|
-
sleep(1) unless @mutex.synchronize { @queue.any? }
|
40
|
-
rescue StandardError => e
|
41
|
-
loggable_log(:error, e.message, class: e.class.to_s, backtrace: e.backtrace)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def terminate
|
46
|
-
@mutex.synchronize { @closed = true }
|
47
|
-
@worker&.join
|
48
|
-
end
|
49
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'faraday'
|
3
|
-
require 'getaround_utils/utils/async_queue'
|
4
|
-
|
5
|
-
class GetaroundUtils::Utils::CapturReporter < GetaroundUtils::Utils::AsyncQueue
|
6
|
-
CAPTUR_URL = ENV['CAPTUR_URL']
|
7
|
-
|
8
|
-
def perform(events)
|
9
|
-
return unless CAPTUR_URL&.match('^https?://')
|
10
|
-
|
11
|
-
Faraday.post(CAPTUR_URL) do |req|
|
12
|
-
req.options[:open_timeout] = 1
|
13
|
-
req.options[:timeout] = 1
|
14
|
-
req.headers = { 'Content-Type': 'application/json' }
|
15
|
-
req.body = JSON.generate(events: events, metas: metas)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def metas
|
20
|
-
{}
|
21
|
-
end
|
22
|
-
|
23
|
-
def push(uuid:, type:, anonymous_id:, timestamp: nil, attributes: {})
|
24
|
-
super(
|
25
|
-
uuid: uuid,
|
26
|
-
type: type,
|
27
|
-
timestamp: timestamp || Time.now.iso8601,
|
28
|
-
anonymous_id: anonymous_id,
|
29
|
-
attributes: attributes,
|
30
|
-
)
|
31
|
-
end
|
32
|
-
end
|