active_record-tracer 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
+ SHA1:
3
+ metadata.gz: 3de6b0a32b1ee458de56fe23f721e2b535d068b5
4
+ data.tar.gz: a4d6a8cbaa4e6b91aa3145c32649a2f5c19388ee
5
+ SHA512:
6
+ metadata.gz: 6f8fc82999537bb3cd0e0db8240c3f633d67b8d7f908a631c8edbad606ed76ede83eb02f8e5043a5313bf19e15a3965048de0edb552f7928099d0ae669c2a53a
7
+ data.tar.gz: d9a50c9e6202ac1f758a06791655e179a14aceb716052b891dd9bf18f625dfca102612a69c233dd99a97445991908b292d85b91f1a39207bbd8e5de335a9ebb5
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /tracer-test
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,43 @@
1
+ require: rubocop-rspec
2
+
3
+ Style/Documentation:
4
+ Enabled: no
5
+
6
+ Style/IfUnlessModifier:
7
+ Enabled: no
8
+
9
+ RSpec/NestedGroups:
10
+ Max: 4
11
+
12
+ RSpec/ExampleLength:
13
+ Enabled: no
14
+
15
+ RSpec/MultipleExpectations:
16
+ Enabled: no
17
+
18
+ Metrics/BlockLength:
19
+ Enabled: no
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: no
23
+
24
+ Metrics/AbcSize:
25
+ Enabled: no
26
+
27
+ Metrics/ClassLength:
28
+ Enabled: no
29
+
30
+ Metrics/ParameterLists:
31
+ Enabled: no
32
+
33
+ Lint/UnusedMethodArgument:
34
+ Enabled: no
35
+
36
+ Style/FrozenStringLiteralComment:
37
+ Enabled: yes
38
+ EnforcedStyle: always
39
+ Include:
40
+ - 'lib/**/*'
41
+
42
+ Metrics/LineLength:
43
+ Max: 120
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in activerecord-tracer.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_record-tracer (0.1.0)
5
+ activerecord (~> 5.0)
6
+ opentracing (~> 0.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.0)
12
+ activesupport (= 5.2.0)
13
+ activerecord (5.2.0)
14
+ activemodel (= 5.2.0)
15
+ activesupport (= 5.2.0)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.0)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ ast (2.4.0)
24
+ concurrent-ruby (1.0.5)
25
+ diff-lcs (1.3)
26
+ i18n (1.0.1)
27
+ concurrent-ruby (~> 1.0)
28
+ minitest (5.11.3)
29
+ opentracing (0.4.1)
30
+ opentracing_test_tracer (0.1.0)
31
+ opentracing
32
+ parallel (1.12.1)
33
+ parser (2.5.1.0)
34
+ ast (~> 2.4.0)
35
+ powerpack (0.1.2)
36
+ rainbow (3.0.0)
37
+ rake (10.5.0)
38
+ rspec (3.7.0)
39
+ rspec-core (~> 3.7.0)
40
+ rspec-expectations (~> 3.7.0)
41
+ rspec-mocks (~> 3.7.0)
42
+ rspec-core (3.7.1)
43
+ rspec-support (~> 3.7.0)
44
+ rspec-expectations (3.7.0)
45
+ diff-lcs (>= 1.2.0, < 2.0)
46
+ rspec-support (~> 3.7.0)
47
+ rspec-mocks (3.7.0)
48
+ diff-lcs (>= 1.2.0, < 2.0)
49
+ rspec-support (~> 3.7.0)
50
+ rspec-support (3.7.1)
51
+ rubocop (0.54.0)
52
+ parallel (~> 1.10)
53
+ parser (>= 2.5)
54
+ powerpack (~> 0.1)
55
+ rainbow (>= 2.2.2, < 4.0)
56
+ ruby-progressbar (~> 1.7)
57
+ unicode-display_width (~> 1.0, >= 1.0.1)
58
+ rubocop-rspec (1.24.0)
59
+ rubocop (>= 0.53.0)
60
+ ruby-progressbar (1.9.0)
61
+ sqlite3 (1.3.13)
62
+ thread_safe (0.3.6)
63
+ tzinfo (1.2.5)
64
+ thread_safe (~> 0.1)
65
+ unicode-display_width (1.4.0)
66
+
67
+ PLATFORMS
68
+ ruby
69
+
70
+ DEPENDENCIES
71
+ active_record-tracer!
72
+ bundler (~> 1.16)
73
+ opentracing_test_tracer (~> 0.1)
74
+ rake (~> 10.0)
75
+ rspec (~> 3.0)
76
+ rubocop (~> 0.54.0)
77
+ rubocop-rspec (~> 1.24.0)
78
+ sqlite3 (~> 1.3.13)
79
+
80
+ BUNDLED WITH
81
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Indrek Juhkam
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # ActiveRecord::Tracer
2
+
3
+ Adds OpenTracing instrumentation to ActiveRecord
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_record-tracer'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require 'opentracing'
17
+ OpenTracing.global_tracer = TracerImplementation.new
18
+
19
+ require 'active_record/tracer'
20
+ ActiveRecord::Tracer.instrument
21
+ ```
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/activerecord-tracer.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ RuboCop::RakeTask.new(:rubocop)
8
+
9
+ task default: %i[rubocop spec]
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'active_record/tracer/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'active_record-tracer'
7
+ spec.version = ActiveRecord::Tracer::VERSION
8
+ spec.authors = ['SaleMove TechMovers']
9
+ spec.email = ['techmovers@salemove.com']
10
+
11
+ spec.summary = 'ActiveRecord OpenTracing tracer'
12
+ spec.description = ''
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'opentracing_test_tracer', '~> 0.1'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rubocop', '~> 0.54.0'
28
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.24.0'
29
+ spec.add_development_dependency 'sqlite3', '~> 1.3.13'
30
+
31
+ spec.add_dependency 'activerecord', '~> 5.0'
32
+ spec.add_dependency 'opentracing', '~> 0.3'
33
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'active_record/tracer'
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/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
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'opentracing'
5
+
6
+ require 'active_record/tracer/version'
7
+ require 'active_record/tracer/processor'
8
+
9
+ module ActiveRecord
10
+ module Tracer
11
+ def self.instrument(tracer: OpenTracing.global_tracer)
12
+ processor = Processor.new(tracer)
13
+
14
+ ActiveSupport::Notifications.subscribe('sql.active_record') do |*args|
15
+ processor.call(*args)
16
+ end
17
+
18
+ self
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module Tracer
5
+ class Processor
6
+ DEFAULT_OPERATION_NAME = 'sql.query'.freeze
7
+ COMPONENT_NAME = 'ActiveRecord'.freeze
8
+ SPAN_KIND = 'client'.freeze
9
+ DB_TYPE = 'sql'.freeze
10
+
11
+ def initialize(tracer)
12
+ @tracer = tracer
13
+ end
14
+
15
+ def call(_event_name, start, finish, _id, payload)
16
+ span = @tracer.start_span(
17
+ payload[:name] || DEFAULT_OPERATION_NAME,
18
+ start_time: start,
19
+ tags: {
20
+ component: COMPONENT_NAME,
21
+ :'span.kind' => SPAN_KIND,
22
+ :'db.instance' => db_instance,
23
+ :'db.cached' => payload.fetch(:cached, false),
24
+ :'db.statement' => payload.fetch(:sql).squish,
25
+ :'db.type' => DB_TYPE
26
+ }
27
+ )
28
+
29
+ if (exception = payload[:exception_object])
30
+ span.set_tag(:error, true)
31
+ span.log_kv(
32
+ event: 'error',
33
+ :'error.kind' => exception.class.to_s,
34
+ :'error.object' => exception,
35
+ message: exception.message,
36
+ stack: exception.backtrace.join("\n")
37
+ )
38
+ end
39
+
40
+ span.finish(end_time: finish)
41
+ end
42
+
43
+ private
44
+
45
+ def db_instance
46
+ @db_instance ||= begin
47
+ connection_config = ActiveRecord::Base.connection_config
48
+ username = connection_config[:username]
49
+ host = connection_config[:host]
50
+ database = connection_config.fetch(:database)
51
+ vendor = connection_config.fetch(:adapter)
52
+
53
+ str = String.new('')
54
+ str << "#{vendor}://"
55
+ str << username if username
56
+ str << "@#{host}" if host
57
+ str << "/#{database}"
58
+ str
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module Tracer
5
+ VERSION = '0.1.0'.freeze
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_record-tracer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - SaleMove TechMovers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opentracing_test_tracer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.54.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.54.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.24.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.24.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: sqlite3
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.3.13
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.3.13
111
+ - !ruby/object:Gem::Dependency
112
+ name: activerecord
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '5.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '5.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: opentracing
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.3'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.3'
139
+ description: ''
140
+ email:
141
+ - techmovers@salemove.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".rubocop.yml"
149
+ - ".travis.yml"
150
+ - Gemfile
151
+ - Gemfile.lock
152
+ - LICENSE.txt
153
+ - README.md
154
+ - Rakefile
155
+ - active_record-tracer.gemspec
156
+ - bin/console
157
+ - bin/setup
158
+ - lib/active_record/tracer.rb
159
+ - lib/active_record/tracer/processor.rb
160
+ - lib/active_record/tracer/version.rb
161
+ homepage: ''
162
+ licenses:
163
+ - MIT
164
+ metadata: {}
165
+ post_install_message:
166
+ rdoc_options: []
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ required_rubygems_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '0'
179
+ requirements: []
180
+ rubyforge_project:
181
+ rubygems_version: 2.6.11
182
+ signing_key:
183
+ specification_version: 4
184
+ summary: ActiveRecord OpenTracing tracer
185
+ test_files: []