traxor 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4f38d4700fc78ffda8d70ee24a88781e81aeca12b7092e67ca158036975811f5
4
+ data.tar.gz: d3d03579b0a62cc0f8a0843b73cb56eea94342a20f430884c54ad240eb5a9381
5
+ SHA512:
6
+ metadata.gz: d4f7a77b434169c993c5715d4448d1dbc3c2d021e6bce2a4b1c5842aaf76ceb3a31d44cc54324f63077316f0e30bee10e3ba73c1a91ae904c0cddd70dfc38953
7
+ data.tar.gz: 4fb15f2dac7b910e2f25a99ea132d854b185d250b86bbbe4f9370f9145274e9571f18e6efc57ea77755b11d5fe58408235d48f8960b9609b6b68d6bb8a3b6675
@@ -0,0 +1,48 @@
1
+ version: 2
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: circleci/ruby:2.5.1-node
6
+ environment:
7
+ RAILS_ENV: test
8
+
9
+ working_directory: ~/repo
10
+
11
+ steps:
12
+ - checkout
13
+
14
+ - restore_cache:
15
+ keys:
16
+ - v1-dependencies-{{ checksum "Gemfile.lock" }}
17
+ # fallback to using the latest cache if no exact match is found
18
+ - v1-dependencies-
19
+
20
+ - run:
21
+ name: Bundle Install
22
+ command: bundle install --deployment --jobs 4 --retry 3
23
+
24
+ - save_cache:
25
+ paths:
26
+ - ./vendor/bundle
27
+ key: v1-dependencies-{{ checksum "Gemfile.lock" }}
28
+
29
+ - run:
30
+ name: Setup Code Climate test-reporter
31
+ command: |
32
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
33
+ chmod +x ./cc-test-reporter
34
+
35
+ - run:
36
+ name: RSpec
37
+ command: |
38
+ mkdir results
39
+ bundle exec rspec spec --order random --profile --format documentation --format RspecJunitFormatter --out results/rspec.xml
40
+ ./cc-test-reporter format-coverage -t simplecov coverage/.resultset.json
41
+ ./cc-test-reporter upload-coverage
42
+
43
+ - store_test_results:
44
+ path: results
45
+ - store_artifacts:
46
+ path: results
47
+ - store_artifacts:
48
+ path: coverage
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,212 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ traxor (0.1.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (5.2.0)
11
+ actionpack (= 5.2.0)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailer (5.2.0)
15
+ actionpack (= 5.2.0)
16
+ actionview (= 5.2.0)
17
+ activejob (= 5.2.0)
18
+ mail (~> 2.5, >= 2.5.4)
19
+ rails-dom-testing (~> 2.0)
20
+ actionpack (5.2.0)
21
+ actionview (= 5.2.0)
22
+ activesupport (= 5.2.0)
23
+ rack (~> 2.0)
24
+ rack-test (>= 0.6.3)
25
+ rails-dom-testing (~> 2.0)
26
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
27
+ actionview (5.2.0)
28
+ activesupport (= 5.2.0)
29
+ builder (~> 3.1)
30
+ erubi (~> 1.4)
31
+ rails-dom-testing (~> 2.0)
32
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
33
+ activejob (5.2.0)
34
+ activesupport (= 5.2.0)
35
+ globalid (>= 0.3.6)
36
+ activemodel (5.2.0)
37
+ activesupport (= 5.2.0)
38
+ activerecord (5.2.0)
39
+ activemodel (= 5.2.0)
40
+ activesupport (= 5.2.0)
41
+ arel (>= 9.0)
42
+ activestorage (5.2.0)
43
+ actionpack (= 5.2.0)
44
+ activerecord (= 5.2.0)
45
+ marcel (~> 0.3.1)
46
+ activesupport (5.2.0)
47
+ concurrent-ruby (~> 1.0, >= 1.0.2)
48
+ i18n (>= 0.7, < 2)
49
+ minitest (~> 5.1)
50
+ tzinfo (~> 1.1)
51
+ arel (9.0.0)
52
+ ast (2.4.0)
53
+ axiom-types (0.1.1)
54
+ descendants_tracker (~> 0.0.4)
55
+ ice_nine (~> 0.11.0)
56
+ thread_safe (~> 0.3, >= 0.3.1)
57
+ builder (3.2.3)
58
+ byebug (10.0.2)
59
+ codeclimate-engine-rb (0.4.1)
60
+ virtus (~> 1.0)
61
+ coderay (1.1.2)
62
+ coercible (1.0.0)
63
+ descendants_tracker (~> 0.0.1)
64
+ concurrent-ruby (1.0.5)
65
+ connection_pool (2.2.1)
66
+ crass (1.0.4)
67
+ descendants_tracker (0.0.4)
68
+ thread_safe (~> 0.3, >= 0.3.1)
69
+ diff-lcs (1.3)
70
+ docile (1.3.0)
71
+ equalizer (0.0.11)
72
+ erubi (1.7.1)
73
+ globalid (0.4.1)
74
+ activesupport (>= 4.2.0)
75
+ i18n (1.0.1)
76
+ concurrent-ruby (~> 1.0)
77
+ ice_nine (0.11.2)
78
+ json (2.1.0)
79
+ loofah (2.2.2)
80
+ crass (~> 1.0.2)
81
+ nokogiri (>= 1.5.9)
82
+ mail (2.7.0)
83
+ mini_mime (>= 0.1.1)
84
+ marcel (0.3.2)
85
+ mimemagic (~> 0.3.2)
86
+ method_source (0.9.0)
87
+ mimemagic (0.3.2)
88
+ mini_mime (1.0.0)
89
+ mini_portile2 (2.3.0)
90
+ minitest (5.11.3)
91
+ nio4r (2.3.0)
92
+ nokogiri (1.8.2)
93
+ mini_portile2 (~> 2.3.0)
94
+ parallel (1.12.1)
95
+ parser (2.5.1.0)
96
+ ast (~> 2.4.0)
97
+ powerpack (0.1.1)
98
+ pry (0.11.3)
99
+ coderay (~> 1.1.0)
100
+ method_source (~> 0.9.0)
101
+ pry-byebug (3.6.0)
102
+ byebug (~> 10.0)
103
+ pry (~> 0.10)
104
+ rack (2.0.4)
105
+ rack-protection (2.0.1)
106
+ rack
107
+ rack-test (1.0.0)
108
+ rack (>= 1.0, < 3)
109
+ rails (5.2.0)
110
+ actioncable (= 5.2.0)
111
+ actionmailer (= 5.2.0)
112
+ actionpack (= 5.2.0)
113
+ actionview (= 5.2.0)
114
+ activejob (= 5.2.0)
115
+ activemodel (= 5.2.0)
116
+ activerecord (= 5.2.0)
117
+ activestorage (= 5.2.0)
118
+ activesupport (= 5.2.0)
119
+ bundler (>= 1.3.0)
120
+ railties (= 5.2.0)
121
+ sprockets-rails (>= 2.0.0)
122
+ rails-dom-testing (2.0.3)
123
+ activesupport (>= 4.2.0)
124
+ nokogiri (>= 1.6)
125
+ rails-html-sanitizer (1.0.4)
126
+ loofah (~> 2.2, >= 2.2.2)
127
+ railties (5.2.0)
128
+ actionpack (= 5.2.0)
129
+ activesupport (= 5.2.0)
130
+ method_source
131
+ rake (>= 0.8.7)
132
+ thor (>= 0.18.1, < 2.0)
133
+ rainbow (3.0.0)
134
+ rake (12.3.1)
135
+ redis (4.0.1)
136
+ reek (4.8.1)
137
+ codeclimate-engine-rb (~> 0.4.0)
138
+ parser (>= 2.5.0.0, < 2.6)
139
+ rainbow (>= 2.0, < 4.0)
140
+ rspec (3.7.0)
141
+ rspec-core (~> 3.7.0)
142
+ rspec-expectations (~> 3.7.0)
143
+ rspec-mocks (~> 3.7.0)
144
+ rspec-core (3.7.1)
145
+ rspec-support (~> 3.7.0)
146
+ rspec-expectations (3.7.0)
147
+ diff-lcs (>= 1.2.0, < 2.0)
148
+ rspec-support (~> 3.7.0)
149
+ rspec-mocks (3.7.0)
150
+ diff-lcs (>= 1.2.0, < 2.0)
151
+ rspec-support (~> 3.7.0)
152
+ rspec-support (3.7.1)
153
+ rspec_junit_formatter (0.3.0)
154
+ rspec-core (>= 2, < 4, != 2.12.0)
155
+ rubocop (0.55.0)
156
+ parallel (~> 1.10)
157
+ parser (>= 2.5)
158
+ powerpack (~> 0.1)
159
+ rainbow (>= 2.2.2, < 4.0)
160
+ ruby-progressbar (~> 1.7)
161
+ unicode-display_width (~> 1.0, >= 1.0.1)
162
+ ruby-progressbar (1.9.0)
163
+ sidekiq (5.1.3)
164
+ concurrent-ruby (~> 1.0)
165
+ connection_pool (~> 2.2, >= 2.2.0)
166
+ rack-protection (>= 1.5.0)
167
+ redis (>= 3.3.5, < 5)
168
+ simplecov (0.16.1)
169
+ docile (~> 1.1)
170
+ json (>= 1.8, < 3)
171
+ simplecov-html (~> 0.10.0)
172
+ simplecov-html (0.10.2)
173
+ sprockets (3.7.1)
174
+ concurrent-ruby (~> 1.0)
175
+ rack (> 1, < 3)
176
+ sprockets-rails (3.2.1)
177
+ actionpack (>= 4.0)
178
+ activesupport (>= 4.0)
179
+ sprockets (>= 3.0.0)
180
+ thor (0.20.0)
181
+ thread_safe (0.3.6)
182
+ tzinfo (1.2.5)
183
+ thread_safe (~> 0.1)
184
+ unicode-display_width (1.3.1)
185
+ virtus (1.0.5)
186
+ axiom-types (~> 0.1)
187
+ coercible (~> 1.0)
188
+ descendants_tracker (~> 0.0, >= 0.0.3)
189
+ equalizer (~> 0.0, >= 0.0.9)
190
+ websocket-driver (0.7.0)
191
+ websocket-extensions (>= 0.1.0)
192
+ websocket-extensions (0.1.3)
193
+
194
+ PLATFORMS
195
+ ruby
196
+
197
+ DEPENDENCIES
198
+ bundler
199
+ pry
200
+ pry-byebug
201
+ rails
202
+ rake
203
+ reek
204
+ rspec
205
+ rspec_junit_formatter
206
+ rubocop
207
+ sidekiq
208
+ simplecov
209
+ traxor!
210
+
211
+ BUNDLED WITH
212
+ 1.16.1
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Traxor [![CircleCI](https://circleci.com/gh/ketiko/traxor.svg?style=svg&circle-token=fd1e0d401eda8de60d31ca3dbb5fb066a71a9b9f)](https://circleci.com/gh/ketiko/traxor) [![Maintainability](https://api.codeclimate.com/v1/badges/d812a63d184fb6c88dbd/maintainability)](https://codeclimate.com/github/ketiko/traxor/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/d812a63d184fb6c88dbd/test_coverage)](https://codeclimate.com/github/ketiko/traxor/test_coverage)
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/traxor`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'traxor'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install traxor
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/traxor.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'code_climate_reek' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('reek', 'code_climate_reek')
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'traxor'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rake', 'rake')
data/bin/reek ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'reek' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('reek', 'reek')
data/bin/rspec ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rspec-core', 'rspec')
data/bin/rubocop ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require 'pathname'
12
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path('bundle', __dir__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 150) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require 'rubygems'
27
+ require 'bundler/setup'
28
+
29
+ load Gem.bin_path('rubocop', 'rubocop')
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/traxor.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'active_support/configurable'
2
+ require 'active_support/inflector/inflections'
3
+ require 'logger'
4
+ require 'traxor/metric'
5
+ require 'traxor/rails' if defined?(Rails)
6
+ require 'traxor/sidekiq' if defined?(Sidekiq)
7
+ require 'traxor/version'
8
+
9
+ module Traxor
10
+ include ActiveSupport::Configurable
11
+ config_accessor :logger do
12
+ Logger.new(STDOUT).tap do |l|
13
+ l.level = Logger::INFO
14
+ end
15
+ end
16
+
17
+ def self.configure
18
+ yield config
19
+ end
20
+
21
+ def self.normalize_name(value)
22
+ value.to_s.gsub(/::/, '.').underscore
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ module Traxor
2
+ module Metric
3
+ def self.count(name, value, tags = {})
4
+ logger.info("count##{name}=#{value} #{tag_string(tags)}".strip)
5
+ end
6
+
7
+ def self.measure(name, value, tags = {})
8
+ logger.info("measure##{name}=#{value} #{tag_string(tags)}".strip)
9
+ end
10
+
11
+ def self.sample(name, value, tags = {})
12
+ logger.info("sample##{name}=#{value} #{tag_string(tags)}".strip)
13
+ end
14
+
15
+ def self.tag_string(tags)
16
+ tags.map do |tag_name, tag_value|
17
+ "tag##{tag_name}=#{tag_value}"
18
+ end.join(' ')
19
+ end
20
+
21
+ def self.logger
22
+ @logger ||= Traxor.config.logger
23
+ end
24
+ end
25
+ end
@@ -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
+ if times.all? { |t| env[t].present? }
23
+ pre_time = (env['traxor.rack.middleware.pre_middleware_end'].to_f - env['traxor.rack.middleware.pre_middleware_start'].to_f)
24
+ post_time = (env['traxor.rack.middleware.post_middleware_end'].to_f - env['traxor.rack.middleware.post_middleware_start'].to_f)
25
+ middleware_time = (pre_time + post_time) * 1_000
26
+ total_time = (env['traxor.rack.middleware.post_middleware_end'].to_f - env['traxor.rack.middleware.pre_middleware_start'].to_f) * 1_000
27
+
28
+ tags = {}
29
+ if controller
30
+ method = env['REQUEST_METHOD'].to_s
31
+ tags = { controller: Traxor.normalize_name(controller.class), action: Traxor.normalize_name(controller.action_name), method: Traxor.normalize_name(method) }
32
+ controller_path = tags.values.join('.')
33
+
34
+ Metric.measure "rack.request.middleware.duration.#{controller_path}", "#{middleware_time.round(2)}ms", tags
35
+ Metric.measure "rack.request.duration.#{controller_path}", "#{total_time.round(2)}ms", tags
36
+ Metric.count 'rack.request.count', 1, tags
37
+ Metric.count "rack.request.count.#{controller_path}", 1, tags
38
+ end
39
+
40
+ Metric.measure 'rack.request.middleware.duration', "#{middleware_time.round(2)}ms", tags
41
+ Metric.measure 'rack.request.duration', "#{total_time.round(2)}ms", tags
42
+ end
43
+
44
+ Metric.count 'rack.request.count', 1
45
+
46
+ [status, headers, body]
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,30 @@
1
+ module Traxor
2
+ class Rails < ::Rails::Engine
3
+ initializer 'traxor.setup' do |app|
4
+ Traxor.configure do |config|
5
+ config.logger = ::Rails.logger
6
+ end
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
+
13
+ ActiveSupport.on_load :action_controller do
14
+ require 'traxor/rails/action_controller'
15
+ end
16
+ ActiveSupport.on_load :active_record do
17
+ require 'traxor/rails/active_record'
18
+ end
19
+ end
20
+
21
+ config.before_configuration do
22
+ if defined?(Sidekiq)
23
+ ::Sidekiq.server_middleware do |chain|
24
+ require 'traxor/sidekiq'
25
+ chain.add Traxor::Sidekiq
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module Traxor
2
+ ActiveSupport::Notifications.subscribe 'process_action.action_controller' do |*args|
3
+ event = ActiveSupport::Notifications::Event.new(*args)
4
+ request = ActionDispatch::Request.new(event.payload[:headers])
5
+ exception = event.payload[:exception]
6
+ controller = normalize_name(event.payload[:controller])
7
+ action = normalize_name(event.payload[:action])
8
+ duration = event.duration || 0.0
9
+ db_runtime = event.payload[:db_runtime] || 0
10
+ view_runtime = event.payload[:view_runtime] || 0
11
+ ruby_runtime = duration.to_f - db_runtime.to_f - view_runtime.to_f
12
+
13
+ controller_path = normalize_name("#{controller.underscore}.#{action.underscore}.#{request.method.downcase}")
14
+ tags = { controller: controller, action: action, method: normalize_name(request.method) }
15
+
16
+ Metric.count 'rails.action_controller.count', 1, tags
17
+ Metric.count "rails.action_controller.count.#{controller_path}", 1, tags
18
+
19
+ Metric.measure 'rails.action_controller.ruby.duration', "#{ruby_runtime.to_f.round(2)}ms", tags
20
+ Metric.measure "rails.action_controller.ruby.duration.#{controller_path}", "#{ruby_runtime.to_f.round(2)}ms", tags
21
+
22
+ Metric.measure 'rails.action_controller.db.duration', "#{db_runtime.to_f.round(2)}ms", tags
23
+ Metric.measure "rails.action_controller.db.duration.#{controller_path}", "#{db_runtime.to_f.round(2)}ms", tags
24
+
25
+ Metric.measure 'rails.action_controller.view.duration', "#{view_runtime.to_f.round(2)}ms", tags
26
+ Metric.measure "rails.action_controller.view.duration.#{controller_path}", "#{view_runtime.to_f.round(2)}ms", tags
27
+
28
+ if exception.present?
29
+ Metric.count 'rails.action_controller.exception.count', 1, tags
30
+ Metric.count "rails.action_controller.exception.count.#{controller_path}", 1, tags
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,26 @@
1
+ module Traxor
2
+ ActiveSupport::Notifications.subscribe 'sql.active_record' do |*args|
3
+ event = ActiveSupport::Notifications::Event.new(*args)
4
+ sql = event.payload[:sql].to_s.strip.upcase
5
+ name = event.payload[:name].to_s.strip.upcase
6
+ next if ['SCHEMA'].any?(name)
7
+ tags = {}
8
+ tags[:name] = normalize_name(name.split.first) if name.length.positive?
9
+
10
+ Metric.count 'rails.active_record.statements.count', 1, tags
11
+ Metric.count 'rails.active_record.statements.select.count', 1, tags if sql.starts_with?('SELECT')
12
+ Metric.count 'rails.active_record.statements.insert.count', 1, tags if sql.starts_with?('INSERT')
13
+ Metric.count 'rails.active_record.statements.update.count', 1, tags if sql.starts_with?('UPDATE')
14
+ Metric.count 'rails.active_record.statements.delete.count', 1, tags if sql.starts_with?('DELETE')
15
+ end
16
+
17
+ ActiveSupport::Notifications.subscribe 'instantiation.active_record' do |*args|
18
+ event = ActiveSupport::Notifications::Event.new(*args)
19
+ record_count = event.payload[:record_count]
20
+ class_name = normalize_name(event.payload[:class_name])
21
+ tags = { class: class_name }
22
+
23
+ Metric.count 'rails.active_record.instantiation.count', record_count, tags
24
+ Metric.count "rails.active_record.instantiation.count.#{class_name}", record_count, tags
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'benchmark'
2
+
3
+ module Traxor
4
+ class Sidekiq
5
+ def call(worker, _job, queue)
6
+ tags = { worker: Traxor.normalize_name(worker.class.name), queue: Traxor.normalize_name(queue) }
7
+ begin
8
+ time = Benchmark.ms do
9
+ yield
10
+ end
11
+ Metric.measure 'sidekiq.worker.duration', "#{time.round(2)}ms", tags
12
+ Metric.measure "sidekiq.worker.duration.#{tags[:worker]}", "#{time.round(2)}ms", tags
13
+ Metric.count 'sidekiq.worker.count', 1, tags
14
+ Metric.count "sidekiq.worker.count.#{tags[:worker]}", 1, tags
15
+ rescue StandardError
16
+ Metric.count 'sidekiq.worker.exception.count', 1, tags
17
+ Metric.count "sidekiq.worker.exception.count.#{tags[:worker]}", 1, tags
18
+ raise
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Traxor
2
+ VERSION = '0.1.0'.freeze
3
+ end
data/traxor.gemspec ADDED
@@ -0,0 +1,36 @@
1
+
2
+ lib = File.expand_path('lib', __dir__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'traxor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'traxor'
8
+ spec.version = Traxor::VERSION
9
+ spec.authors = ['Ryan Hansen']
10
+ spec.email = ['ketiko@gmail.com']
11
+
12
+ spec.summary = 'Log metrics to akkeris platform'
13
+ spec.description = 'Log metrics to akkeris platform'
14
+ spec.homepage = 'https://github.com/ketiko/traxor'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'activesupport'
24
+
25
+ spec.add_development_dependency 'bundler'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'pry-byebug'
28
+ spec.add_development_dependency 'rails'
29
+ spec.add_development_dependency 'rake'
30
+ spec.add_development_dependency 'reek'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rspec_junit_formatter'
33
+ spec.add_development_dependency 'rubocop'
34
+ spec.add_development_dependency 'sidekiq'
35
+ spec.add_development_dependency 'simplecov'
36
+ end
metadata ADDED
@@ -0,0 +1,236 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: traxor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Hansen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: reek
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec_junit_formatter
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: sidekiq
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ description: Log metrics to akkeris platform
182
+ email:
183
+ - ketiko@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".circleci/config.yml"
189
+ - ".gitignore"
190
+ - ".rspec"
191
+ - ".travis.yml"
192
+ - Gemfile
193
+ - Gemfile.lock
194
+ - README.md
195
+ - Rakefile
196
+ - bin/code_climate_reek
197
+ - bin/console
198
+ - bin/rake
199
+ - bin/reek
200
+ - bin/rspec
201
+ - bin/rubocop
202
+ - bin/setup
203
+ - lib/traxor.rb
204
+ - lib/traxor/metric.rb
205
+ - lib/traxor/rack/middleware/post.rb
206
+ - lib/traxor/rack/middleware/pre.rb
207
+ - lib/traxor/rails.rb
208
+ - lib/traxor/rails/action_controller.rb
209
+ - lib/traxor/rails/active_record.rb
210
+ - lib/traxor/sidekiq.rb
211
+ - lib/traxor/version.rb
212
+ - traxor.gemspec
213
+ homepage: https://github.com/ketiko/traxor
214
+ licenses: []
215
+ metadata: {}
216
+ post_install_message:
217
+ rdoc_options: []
218
+ require_paths:
219
+ - lib
220
+ required_ruby_version: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - ">="
223
+ - !ruby/object:Gem::Version
224
+ version: '0'
225
+ required_rubygems_version: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 2.7.6
233
+ signing_key:
234
+ specification_version: 4
235
+ summary: Log metrics to akkeris platform
236
+ test_files: []