activerecord-opentracing 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ed89ef2d89d97aaf7687a8316fbe7b49d635f26f
4
+ data.tar.gz: c5c01c72da5576edfad1b25931c689c451077f1b
5
+ SHA512:
6
+ metadata.gz: 595053afc7b8a8104aff3b2bf52db6f2b86188d2d0cb9ef52592e235783a8b0266af4df593fbecd5d6522f729be5c981327af0391051f5e35b6e951cd82f5224
7
+ data.tar.gz: b011e5bb779d7d86f723308396c3edfd8a89d65136f104c7b6323c62f77205ddb588bbea6ff82269b14bc09e7d3e08e7a523aa7a04b11127b22590840779d34d
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /tracer-test
10
+ /Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .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,46 @@
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/FilePath:
16
+ Enabled: no
17
+
18
+ RSpec/MultipleExpectations:
19
+ Enabled: no
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: no
23
+
24
+ Metrics/MethodLength:
25
+ Enabled: no
26
+
27
+ Metrics/AbcSize:
28
+ Enabled: no
29
+
30
+ Metrics/ClassLength:
31
+ Enabled: no
32
+
33
+ Metrics/ParameterLists:
34
+ Enabled: no
35
+
36
+ Lint/UnusedMethodArgument:
37
+ Enabled: no
38
+
39
+ Style/FrozenStringLiteralComment:
40
+ Enabled: yes
41
+ EnforcedStyle: always
42
+ Include:
43
+ - 'lib/**/*'
44
+
45
+ Metrics/LineLength:
46
+ 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/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::OpenTracing
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 'activerecord-opentracing'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```ruby
16
+ require 'opentracing'
17
+ OpenTracing.global_tracer = TracerImplementation.new
18
+
19
+ require 'active_record/opentracing'
20
+ ActiveRecord::OpenTracing.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/opentracing/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'activerecord-opentracing'
7
+ spec.version = ActiveRecord::OpenTracing::VERSION
8
+ spec.authors = ['SaleMove TechMovers']
9
+ spec.email = ['techmovers@salemove.com']
10
+
11
+ spec.summary = 'ActiveRecord OpenTracing intrumenter'
12
+ spec.description = ''
13
+ spec.homepage = 'https://github.com/salemove/ruby-activerecord-opentracing'
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/opentracing'
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/opentracing/version'
7
+ require 'active_record/opentracing/processor'
8
+
9
+ module ActiveRecord
10
+ module OpenTracing
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,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module OpenTracing
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
+ :'peer.address' => db_address
27
+ }
28
+ )
29
+
30
+ if (exception = payload[:exception_object])
31
+ span.set_tag(:error, true)
32
+ span.log_kv(
33
+ event: 'error',
34
+ :'error.kind' => exception.class.to_s,
35
+ :'error.object' => exception,
36
+ message: exception.message,
37
+ stack: exception.backtrace.join("\n")
38
+ )
39
+ end
40
+
41
+ span.finish(end_time: finish)
42
+ end
43
+
44
+ private
45
+
46
+ def db_instance
47
+ @db_instance ||= db_config.fetch(:database)
48
+ end
49
+
50
+ def db_address
51
+ @db_address ||= begin
52
+ connection_config = ActiveRecord::Base.connection_config
53
+ username = connection_config[:username]
54
+ host = connection_config[:host]
55
+ database = connection_config.fetch(:database)
56
+ vendor = connection_config.fetch(:adapter)
57
+
58
+ str = String.new('')
59
+ str << "#{vendor}://"
60
+ str << username if username
61
+ str << "@#{host}" if host
62
+ str << "/#{database}"
63
+ str
64
+ end
65
+ end
66
+
67
+ def db_config
68
+ @db_config ||= ActiveRecord::Base.connection_config
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module OpenTracing
5
+ VERSION = '0.2.0'.freeze
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-opentracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - SaleMove TechMovers
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-09 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
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - activerecord-opentracing.gemspec
155
+ - bin/console
156
+ - bin/setup
157
+ - lib/active_record/opentracing.rb
158
+ - lib/active_record/opentracing/processor.rb
159
+ - lib/active_record/opentracing/version.rb
160
+ homepage: https://github.com/salemove/ruby-activerecord-opentracing
161
+ licenses:
162
+ - MIT
163
+ metadata: {}
164
+ post_install_message:
165
+ rdoc_options: []
166
+ require_paths:
167
+ - lib
168
+ required_ruby_version: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 2.6.11
181
+ signing_key:
182
+ specification_version: 4
183
+ summary: ActiveRecord OpenTracing intrumenter
184
+ test_files: []