signalfx-activerecord-opentracing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a3536f2887d5c9bfa482fe57a322eb5d9f33b56d0b2c5b53a2b6b7eddd2174ab
4
+ data.tar.gz: 962fac6ba15d260d9833a38a834fe97e67ace240e8bd2958b089776ccaa616f1
5
+ SHA512:
6
+ metadata.gz: 21bf1688f74f04157479ac3e84e149b59a19c4805dc48347dc270a7913a703bcc892f1bcb705bd5b1dba7cbd261d557cf96175535d10c20031e76623f0998e35
7
+ data.tar.gz: 6cf2a3a3fe38c6ae622f8582af48537501a00fb4f5d9d07bb8a798aa1a4b9cd1d6e3ae14b5d95ecfd3d423ca56ecfba21c84d766171c2591893658e18fee6112
@@ -0,0 +1,14 @@
1
+ /vendor/
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /tracer-test
11
+ /Gemfile.lock
12
+
13
+ # rspec failure tracking
14
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -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
@@ -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
@@ -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.
@@ -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).
@@ -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 = 'signalfx-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', '~> 2.1'
24
+ spec.add_development_dependency 'signalfx_test_tracer', '~> 0.1.4'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
27
+ spec.add_development_dependency 'rubocop', '~> 0.78.0'
28
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.37.0'
29
+ spec.add_development_dependency 'sqlite3', '~> 1.4.2'
30
+
31
+ spec.add_dependency 'activerecord', '~> 6.0'
32
+ spec.add_dependency 'opentracing', '~> 0.5'
33
+ end
@@ -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__)
@@ -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,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module OpenTracing
5
+ class Processor
6
+ DEFAULT_OPERATION_NAME = 'sql.query'
7
+ COMPONENT_NAME = 'ActiveRecord'
8
+ SPAN_KIND = 'client'
9
+ DB_TYPE = 'sql'
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.record_exception(exception)
32
+ end
33
+
34
+ span.finish(end_time: finish)
35
+ end
36
+
37
+ private
38
+
39
+ def db_instance
40
+ @db_instance ||= db_config.fetch(:database)
41
+ end
42
+
43
+ def db_address
44
+ @db_address ||= begin
45
+ connection_config = ActiveRecord::Base.connection_config
46
+ username = connection_config[:username]
47
+ host = connection_config[:host]
48
+ database = connection_config.fetch(:database)
49
+ vendor = connection_config.fetch(:adapter)
50
+
51
+ str = String.new('')
52
+ str << "#{vendor}://"
53
+ str << username if username
54
+ str << "@#{host}" if host
55
+ str << "/#{database}"
56
+ str
57
+ end
58
+ end
59
+
60
+ def db_config
61
+ @db_config ||= ActiveRecord::Base.connection_config
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveRecord
4
+ module OpenTracing
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: signalfx-activerecord-opentracing
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: 2020-12-04 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: '2.1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: signalfx_test_tracer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.4
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.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.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.9.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.9.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.78.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.78.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.37.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.37.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.4.2
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.4.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: activerecord
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '6.0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '6.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.5'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.5'
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
+ rubygems_version: 3.1.2
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: ActiveRecord OpenTracing intrumenter
183
+ test_files: []