traxor 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/traxor/rack/middleware/post.rb +19 -0
- data/lib/traxor/rack/middleware/pre.rb +51 -0
- data/lib/traxor/rails.rb +5 -0
- data/lib/traxor/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a0dcf0f96b5856efd0d7cdae4a792060be57aa7a007d0ea82367be71aa10d52c
|
4
|
+
data.tar.gz: 2bd5f98078fa3a605f9e6e155d0bcb7cd44dce8eccd08c53ed5c82cef67b06c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c9353849f1c564dcfeb06a4bed35630a59d857fa69f35d1e943da06f4949755420610ce6be31ba782fce1cedc30e7f3b3572de7e832ae9ed75d1e017d11817f5
|
7
|
+
data.tar.gz: f322dad148a2975afc938ba4576acb1f2cfb7bd905d0255a96c972bd1ee3671882a494f87e6811350e2b443191e94b12bf43a8e1d53be349b2e07d33c7cd864f
|
data/Gemfile.lock
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Traxor
|
2
|
+
module Rack
|
3
|
+
module Middleware
|
4
|
+
class Post
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env['traxor.rack.middleware.pre_middleware_end'] = Time.now.to_f
|
11
|
+
status, headers, response = @app.call(env)
|
12
|
+
env['traxor.rack.middleware.post_middleware_start'] = Time.now.to_f
|
13
|
+
|
14
|
+
[status, headers, response]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Traxor
|
2
|
+
module Rack
|
3
|
+
module Middleware
|
4
|
+
class Pre
|
5
|
+
def initialize(app)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env['traxor.rack.middleware.pre_middleware_start'] = Time.now.to_f
|
11
|
+
status, headers, body = @app.call(env)
|
12
|
+
env['traxor.rack.middleware.post_middleware_end'] = Time.now.to_f
|
13
|
+
|
14
|
+
controller = env['action_controller.instance']
|
15
|
+
times = [
|
16
|
+
'traxor.rack.middleware.pre_middleware_start',
|
17
|
+
'traxor.rack.middleware.pre_middleware_end',
|
18
|
+
'traxor.rack.middleware.post_middleware_start',
|
19
|
+
'traxor.rack.middleware.post_middleware_end'
|
20
|
+
]
|
21
|
+
|
22
|
+
tags = {}
|
23
|
+
|
24
|
+
if times.all? { |t| env[t].present? }
|
25
|
+
pre_time = (env['traxor.rack.middleware.pre_middleware_end'].to_f - env['traxor.rack.middleware.pre_middleware_start'].to_f)
|
26
|
+
post_time = (env['traxor.rack.middleware.post_middleware_end'].to_f - env['traxor.rack.middleware.post_middleware_start'].to_f)
|
27
|
+
middleware_time = (pre_time + post_time) * 1_000
|
28
|
+
total_time = (env['traxor.rack.middleware.post_middleware_end'].to_f - env['traxor.rack.middleware.pre_middleware_start'].to_f) * 1_000
|
29
|
+
|
30
|
+
if controller
|
31
|
+
method = env['REQUEST_METHOD'].to_s
|
32
|
+
tags = { controller: Traxor.normalize_name(controller.class), action: Traxor.normalize_name(controller.action_name), method: Traxor.normalize_name(method) }
|
33
|
+
controller_path = tags.values.join('.')
|
34
|
+
|
35
|
+
Metric.measure 'rack.request.middleware.duration', "#{middleware_time.round(2)}ms", tags
|
36
|
+
Metric.measure "rack.request.middleware.duration.#{controller_path}", "#{middleware_time.round(2)}ms", tags
|
37
|
+
Metric.measure "rack.request.duration.#{controller_path}", "#{total_time.round(2)}ms", tags
|
38
|
+
Metric.count "rack.request.count.#{controller_path}", 1, tags
|
39
|
+
end
|
40
|
+
|
41
|
+
Metric.measure 'rack.request.duration', "#{total_time.round(2)}ms", tags
|
42
|
+
end
|
43
|
+
|
44
|
+
Metric.count 'rack.request.count', 1, tags
|
45
|
+
|
46
|
+
[status, headers, body]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/traxor/rails.rb
CHANGED
@@ -5,6 +5,11 @@ module Traxor
|
|
5
5
|
config.logger = ::Rails.logger
|
6
6
|
end
|
7
7
|
|
8
|
+
require 'traxor/rack/middleware/pre'
|
9
|
+
require 'traxor/rack/middleware/post'
|
10
|
+
app.config.middleware.insert 0, Traxor::Rack::Middleware::Pre
|
11
|
+
app.config.middleware.use Traxor::Rack::Middleware::Post
|
12
|
+
|
8
13
|
ActiveSupport.on_load :action_controller do
|
9
14
|
require 'traxor/rails/action_controller'
|
10
15
|
end
|
data/lib/traxor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traxor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Hansen
|
@@ -217,6 +217,8 @@ files:
|
|
217
217
|
- lib/traxor.rb
|
218
218
|
- lib/traxor/faraday.rb
|
219
219
|
- lib/traxor/metric.rb
|
220
|
+
- lib/traxor/rack/middleware/post.rb
|
221
|
+
- lib/traxor/rack/middleware/pre.rb
|
220
222
|
- lib/traxor/rails.rb
|
221
223
|
- lib/traxor/rails/action_controller.rb
|
222
224
|
- lib/traxor/rails/action_mailer.rb
|