traxor 0.1.4 → 0.1.5

This diff has not been reviewed by any users.
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: cedd3c6bbff0b1550fed56d2bbbc8aa6d3aa4381b26441ab9382e0cd79ad9d95
4
- data.tar.gz: f3c9c247555018ba407bc8390a1d42d19153e1df8b4db259e180d8ece047d9d4
3
+ metadata.gz: a0dcf0f96b5856efd0d7cdae4a792060be57aa7a007d0ea82367be71aa10d52c
4
+ data.tar.gz: 2bd5f98078fa3a605f9e6e155d0bcb7cd44dce8eccd08c53ed5c82cef67b06c1
5
5
  SHA512:
6
- metadata.gz: 0cc091b94559ec5463d6b1c9ec7133518847305e536fa043ef9b26ec115f2decf36b04a2c77ac4d5e81c60d3bf703a0127abd4143e81eb8533a6dcf39d9f4f25
7
- data.tar.gz: 9227bb0baf351efeef9b2364c2c38dd3d3153c5e8c185d2cdf9ceb4bd9415587386dcf63c149d067afac8add77ec6ccc14cf462f05da3e8f38f0092facde92d2
6
+ metadata.gz: c9353849f1c564dcfeb06a4bed35630a59d857fa69f35d1e943da06f4949755420610ce6be31ba782fce1cedc30e7f3b3572de7e832ae9ed75d1e017d11817f5
7
+ data.tar.gz: f322dad148a2975afc938ba4576acb1f2cfb7bd905d0255a96c972bd1ee3671882a494f87e6811350e2b443191e94b12bf43a8e1d53be349b2e07d33c7cd864f
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- traxor (0.1.4)
4
+ traxor (0.1.5)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Traxor
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  end
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
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