mysql2-instrumentation 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Appraisals +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/mysql2_0.5.0.gemfile +7 -0
- data/gemfiles/mysql2_0.5.0.gemfile.lock +47 -0
- data/gemfiles/mysql2_latest.gemfile +7 -0
- data/gemfiles/mysql2_latest.gemfile.lock +47 -0
- data/lib/mysql2/instrumentation/version.rb +5 -0
- data/lib/mysql2/instrumentation.rb +54 -0
- data/mysql2-instrumentation.gemspec +32 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64239800509e85aa70c2ea7031ca17976d76fdc2
|
4
|
+
data.tar.gz: 32b8fe2b3cb4a178e17a04f8543b1f6ebdf153c6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7cb36a2931a06091c312b3ea718531b537f7bd1c6befc33d16d515a59adc8e4c8d9e9be00ffdddb143af981b7852f08bd7f23d98668ff0897ec4fbcf7f63ab6
|
7
|
+
data.tar.gz: f3c73053232ccbf892af399763103d56a4bdbf0163e6d10188b69dfbd816d9f35dd51048704f0b935950f94098af9c40a37a6dc1ddfa39e7f2db7dad70f67cc8
|
data/.gitignore
ADDED
data/Appraisals
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Ashwin Chandrasekar
|
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,51 @@
|
|
1
|
+
# Mysql2::Instrumentation
|
2
|
+
|
3
|
+
This gem provides OpenTracing autoinstrumentation for [Mysql2](https://github.com/brianmario/mysql2).
|
4
|
+
|
5
|
+
## Supported versions
|
6
|
+
|
7
|
+
- MRI Ruby 2.0 and newer
|
8
|
+
- Mysql2 0.5.0 and newer
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'mysql2-instrumentation'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install mysql2-instrumentation
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
Before creating a new Mysql2 client, add this code:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'mysql2/instrumentation'
|
32
|
+
|
33
|
+
Mysql2::Instrumentation.instrument(tracer: tracer)
|
34
|
+
```
|
35
|
+
|
36
|
+
`instrument` takes an optional parameter, `:tracer`, which sets the OpenTracing
|
37
|
+
tracer to use. If one is not provided, the `OpenTracing.global_tracer` is used.
|
38
|
+
|
39
|
+
## Development
|
40
|
+
|
41
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
42
|
+
|
43
|
+
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).
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/signalfx/mysql2-instrumentation.
|
48
|
+
|
49
|
+
## License
|
50
|
+
|
51
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mysql2/instrumentation"
|
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,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
mysql2-instrumentation (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (2.2.0)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
thor (>= 0.14.0)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
mysql2 (0.5.0)
|
15
|
+
opentracing (0.4.3)
|
16
|
+
opentracing_test_tracer (0.1.1)
|
17
|
+
opentracing
|
18
|
+
rake (10.5.0)
|
19
|
+
rspec (3.8.0)
|
20
|
+
rspec-core (~> 3.8.0)
|
21
|
+
rspec-expectations (~> 3.8.0)
|
22
|
+
rspec-mocks (~> 3.8.0)
|
23
|
+
rspec-core (3.8.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-expectations (3.8.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-mocks (3.8.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-support (3.8.0)
|
32
|
+
thor (0.20.3)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
appraisal (~> 2.2)
|
39
|
+
bundler (~> 1.16)
|
40
|
+
mysql2 (= 0.5.0)
|
41
|
+
mysql2-instrumentation!
|
42
|
+
opentracing_test_tracer (~> 0.1)
|
43
|
+
rake (~> 10.0)
|
44
|
+
rspec (~> 3.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.5
|
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ..
|
3
|
+
specs:
|
4
|
+
mysql2-instrumentation (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
appraisal (2.2.0)
|
10
|
+
bundler
|
11
|
+
rake
|
12
|
+
thor (>= 0.14.0)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
mysql2 (0.5.2)
|
15
|
+
opentracing (0.4.3)
|
16
|
+
opentracing_test_tracer (0.1.1)
|
17
|
+
opentracing
|
18
|
+
rake (10.5.0)
|
19
|
+
rspec (3.8.0)
|
20
|
+
rspec-core (~> 3.8.0)
|
21
|
+
rspec-expectations (~> 3.8.0)
|
22
|
+
rspec-mocks (~> 3.8.0)
|
23
|
+
rspec-core (3.8.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-expectations (3.8.2)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.8.0)
|
28
|
+
rspec-mocks (3.8.0)
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-support (3.8.0)
|
32
|
+
thor (0.20.3)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
appraisal (~> 2.2)
|
39
|
+
bundler (~> 1.16)
|
40
|
+
mysql2
|
41
|
+
mysql2-instrumentation!
|
42
|
+
opentracing_test_tracer (~> 0.1)
|
43
|
+
rake (~> 10.0)
|
44
|
+
rspec (~> 3.0)
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
1.16.5
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'mysql2/instrumentation/version'
|
2
|
+
require 'opentracing'
|
3
|
+
|
4
|
+
module Mysql2
|
5
|
+
module Instrumentation
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
attr_accessor :tracer
|
10
|
+
|
11
|
+
def instrument(tracer: OpenTracing.global_tracer)
|
12
|
+
begin
|
13
|
+
require 'mysql2'
|
14
|
+
rescue LoadError
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
@tracer = tracer
|
19
|
+
|
20
|
+
patch_query unless @instrumented
|
21
|
+
|
22
|
+
@instrumented = true
|
23
|
+
end
|
24
|
+
|
25
|
+
def patch_query
|
26
|
+
::Mysql2::Client.class_eval do
|
27
|
+
|
28
|
+
alias_method :query_original, :query
|
29
|
+
|
30
|
+
def query(sql, options = {})
|
31
|
+
tags = {
|
32
|
+
'component' => 'mysql2',
|
33
|
+
'db.instance' => @query_options.fetch(:database, ''),
|
34
|
+
'db.statement' => sql,
|
35
|
+
'db.user' => @query_options.fetch(:username, ''),
|
36
|
+
'db.type' => 'mysql',
|
37
|
+
'span.kind' => 'client',
|
38
|
+
}
|
39
|
+
|
40
|
+
span = ::Mysql2::Instrumentation.tracer.start_span(sql, tags: tags)
|
41
|
+
query_original(sql, options)
|
42
|
+
rescue => error
|
43
|
+
span.set_tag("error", true)
|
44
|
+
span.log_kv(key: "message", value: error.message)
|
45
|
+
|
46
|
+
raise error
|
47
|
+
ensure
|
48
|
+
span.finish if span
|
49
|
+
end
|
50
|
+
end # class_eval
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "mysql2/instrumentation/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mysql2-instrumentation"
|
8
|
+
spec.version = Mysql2::Instrumentation::VERSION
|
9
|
+
spec.authors = ["Ashwin Chandrasekar"]
|
10
|
+
spec.email = ["achandrasekar@signalfx.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Mysql2 Tracing Instrumentation}
|
13
|
+
spec.description = %q{OpenTracing instrumentation to trace queries made with Mysql2.}
|
14
|
+
spec.homepage = "https://github.com/signalfx/ruby-mysql2-instrumentation"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency "appraisal", "~> 2.2"
|
31
|
+
spec.add_development_dependency "mysql2", "~> 0.5.2"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mysql2-instrumentation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ashwin Chandrasekar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-11 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: appraisal
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.2'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: mysql2
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.2
|
97
|
+
description: OpenTracing instrumentation to trace queries made with Mysql2.
|
98
|
+
email:
|
99
|
+
- achandrasekar@signalfx.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Appraisals
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- bin/console
|
111
|
+
- bin/setup
|
112
|
+
- gemfiles/.bundle/config
|
113
|
+
- gemfiles/mysql2_0.5.0.gemfile
|
114
|
+
- gemfiles/mysql2_0.5.0.gemfile.lock
|
115
|
+
- gemfiles/mysql2_latest.gemfile
|
116
|
+
- gemfiles/mysql2_latest.gemfile.lock
|
117
|
+
- lib/mysql2/instrumentation.rb
|
118
|
+
- lib/mysql2/instrumentation/version.rb
|
119
|
+
- mysql2-instrumentation.gemspec
|
120
|
+
homepage: https://github.com/signalfx/ruby-mysql2-instrumentation
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.6.13
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Mysql2 Tracing Instrumentation
|
144
|
+
test_files: []
|