redis-instrumentation 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: a8d1dd9a6aa8c0a4aa6b9fd5988af8b0e28169d4
4
+ data.tar.gz: 9891668d902bf5462119661664e51cca97c9fd60
5
+ SHA512:
6
+ metadata.gz: 4d4f427caf286cb9c81ca64fdb8721a5c65fd314b378c841bd3c58f0cba8a46a3e0ef01a65f6a022e3976e5d23df822626ff661b2836550130c98654f571d5c2
7
+ data.tar.gz: c8aeb182985266ff38c7de8b8d09c3f7fa0918e44e3e5d8179dec3603ba17e8f5d80a8c45c447e07cfd1e27b9aba9c5bb1584e4196317b0e9e2021b9dcc87674
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Appraisals ADDED
@@ -0,0 +1,11 @@
1
+ appraise 'redis-latest' do
2
+ gem 'redis'
3
+ end
4
+
5
+ appraise 'redis-4.1.0' do
6
+ gem 'redis', '4.1.0'
7
+ end
8
+
9
+ appraise 'redis-4.0.1' do
10
+ gem 'redis', '4.0.1'
11
+ end
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 redis-instrumentation.gemspec
6
+ gemspec
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,49 @@
1
+ # Redis::Instrumentation
2
+
3
+ This gem provides OpenTracing auto-instrumentation for commands send through the Redis client.
4
+
5
+ ## Supported Versions
6
+
7
+ - MRI 2.0 and newer
8
+ - Redis 4.0.1 and newer
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'redis-instrumentation'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install redis-instrumentation
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ require 'redis/instrumentation'
30
+
31
+ Redis::Instrumentation.instrument
32
+ ```
33
+
34
+ `instrument` takes an optional argument, `tracer`, to set a custom OpenTracing
35
+ tracer. It will default to `OpenTracing.global_tracer`.
36
+
37
+ ## Development
38
+
39
+ 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.
40
+
41
+ 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).
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/signalfx/ruby-redis-instrumentation.
46
+
47
+ ## License
48
+
49
+ 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,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "redis/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,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,80 @@
1
+ require "redis/instrumentation/version"
2
+ require "opentracing"
3
+ require "redis"
4
+
5
+ # this is a class instead of module to match how Redis does it
6
+ # otherwise this name will collide
7
+ class Redis
8
+ module Instrumentation
9
+ COMMON_TAGS = {
10
+ 'span.kind' => 'client',
11
+ 'component' => 'ruby-redis',
12
+ 'db.type' => 'redis',
13
+ }.freeze
14
+
15
+ class << self
16
+
17
+ attr_accessor :tracer
18
+
19
+ def instrument(tracer: OpenTracing.global_tracer)
20
+ begin
21
+ require 'redis'
22
+ rescue LoadError => e
23
+ return
24
+ end
25
+
26
+ @tracer = tracer
27
+
28
+ patch_client if !@patched_client
29
+ @patched_client = true
30
+ end
31
+
32
+ def patch_client
33
+ ::Redis::Client.class_eval do
34
+ alias_method :call_original, :call
35
+ alias_method :call_pipeline_original, :call_pipeline
36
+
37
+ def call(command, trace: true)
38
+ tags = ::Redis::Instrumentation::COMMON_TAGS.dup
39
+ tags['db.statement'] = command.join(' ')
40
+ tags['db.instance'] = db
41
+ tags['peer.address'] = "redis://#{host}:#{port}"
42
+
43
+ # command[0] is usually the actual command name
44
+ scope = ::Redis::Instrumentation.tracer.start_active_span("redis.#{command[0]}", tags: tags)
45
+
46
+ call_original(command)
47
+ rescue => e
48
+ if scope
49
+ scope.span.set_tag("error", true)
50
+ scope.span.log_kv(key: "message", value: e.message)
51
+ end
52
+ raise e
53
+ ensure
54
+ scope.close if scope
55
+ end
56
+
57
+ def call_pipeline(pipeline)
58
+ commands = pipeline.commands
59
+ tags = ::Redis::Instrumentation::COMMON_TAGS.dup
60
+ tags['db.statement'] = commands.empty? ? "" : commands.map{ |arr| arr.join(' ') }.join(', ')
61
+ tags['db.instance'] = db
62
+ tags['peer.address'] = "redis://#{host}:#{port}"
63
+
64
+ scope = ::Redis::Instrumentation.tracer.start_active_span("redis.pipelined", tags: tags)
65
+
66
+ call_pipeline_original(pipeline)
67
+ rescue => e
68
+ if scope
69
+ scope.span.set_tag("error", true)
70
+ scope.span.log_kv(key: "message", value: e.message)
71
+ end
72
+ raise e
73
+ ensure
74
+ scope.close if scope
75
+ end
76
+ end
77
+ end # patch_client
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module RedisInstrumentation
2
+ VERSION = "0.1.0"
3
+ 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 "redis/instrumentation/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redis-instrumentation"
8
+ spec.version = RedisInstrumentation::VERSION
9
+ spec.authors = ["Ashwin Chandrasekar"]
10
+ spec.email = ["achandrasekar@signalfx.com"]
11
+
12
+ spec.summary = %q{OpenTracing instrumentation for the Redis Ruby client.}
13
+ spec.homepage = "https://github.com/signalfx/ruby-redis-instrumentation"
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('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "opentracing", "> 0.3"
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "appraisal", "~> 2.2"
30
+ spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
31
+ spec.add_development_dependency "redis", "~> 4.1.0"
32
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis-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-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: opentracing
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
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: opentracing_test_tracer
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: redis
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 4.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 4.1.0
111
+ description:
112
+ email:
113
+ - achandrasekar@signalfx.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".gitignore"
119
+ - Appraisals
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/console
125
+ - bin/setup
126
+ - lib/redis/instrumentation.rb
127
+ - lib/redis/instrumentation/version.rb
128
+ - redis-instrumentation.gemspec
129
+ homepage: https://github.com/signalfx/ruby-redis-instrumentation
130
+ licenses:
131
+ - MIT
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.6.13
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: OpenTracing instrumentation for the Redis Ruby client.
153
+ test_files: []