restclient-instrumentation 0.1.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: c1c1baceda857fdf3902ec7abb4b00e91726b4db
4
+ data.tar.gz: 2a8ba43119fa5942c725d766895ea8e0bbb82fe2
5
+ SHA512:
6
+ metadata.gz: a647b5687ec934895860d477f47beb29b99deae79bae16ca483b0c8f1e9659f69c84d83dcec33c27b5c4913510effaf09605786d85d86cc17c24937c47655493
7
+ data.tar.gz: a85da359bf7e87bbee66d31418feb108ca90b84a0ba8a33bbef932e825cf72167f54cb60cb4cc06d0c890b5a3c9655d14593bec7fec9d51e6b73c9d46a6f1532
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,8 @@
1
+ appraise 'rest-client-latest' do
2
+ gem 'rest-client'
3
+ end
4
+
5
+ appraise 'rest-client-2.0.0' do
6
+ gem 'rest-client', '2.0.0'
7
+ end
8
+
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 restclient-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,56 @@
1
+ # Restclient::Instrumentation
2
+
3
+ This gem provides instrumentation for RestClient requests.
4
+
5
+ ## Supported versions:
6
+
7
+ - MRI 2.0 and newer
8
+ - rest-client 2.0.0 and newer
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'restclient-instrumentation'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install restclient-instrumentation
25
+
26
+ ## Usage
27
+
28
+ To enable the instrumentation and patch RestClient:
29
+
30
+ ```ruby
31
+ require 'restclient/instrumentation'
32
+
33
+ RestClient::Instrumentation.instrument
34
+ ```
35
+
36
+ `instrument` takes two parameters:
37
+ - `propagate`: Enable propagating span contexts through request headers.
38
+ A value must be provided for this keyword argument
39
+ - `tracer`: (Optional) Set an OpenTracing tracer to use.
40
+ Defaults to `OpenTracing.global_tracer`.
41
+
42
+ In the case of an error, the span will be finished and tagged with the error code and message. However, the exception will still be passed up to the caller, and the caller must handle it or at least wait as long as the exporter's flush interval to ensure that the span gets exported.
43
+
44
+ ## Development
45
+
46
+ 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.
47
+
48
+ 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).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/signalfx/ruby-restclient-instrumentation.
53
+
54
+ ## License
55
+
56
+ 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 "restclient/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,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rest-client", "2.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ restclient-instrumentation (0.1.0)
5
+ opentracing (~> 0.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ appraisal (2.2.0)
13
+ bundler
14
+ rake
15
+ thor (>= 0.14.0)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.3)
19
+ domain_name (0.5.20180417)
20
+ unf (>= 0.0.5, < 1.0.0)
21
+ hashdiff (0.3.7)
22
+ http-cookie (1.0.3)
23
+ domain_name (~> 0.5)
24
+ mime-types (3.2.2)
25
+ mime-types-data (~> 3.2015)
26
+ mime-types-data (3.2018.0812)
27
+ netrc (0.11.0)
28
+ opentracing (0.4.3)
29
+ opentracing_test_tracer (0.1.1)
30
+ opentracing
31
+ public_suffix (3.0.3)
32
+ rake (10.5.0)
33
+ rest-client (2.0.0)
34
+ http-cookie (>= 1.0.2, < 2.0)
35
+ mime-types (>= 1.16, < 4.0)
36
+ netrc (~> 0.8)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.0)
50
+ safe_yaml (1.0.4)
51
+ thor (0.20.3)
52
+ unf (0.1.4)
53
+ unf_ext
54
+ unf_ext (0.0.7.5)
55
+ webmock (3.4.2)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+ hashdiff
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ appraisal (~> 2.2)
65
+ bundler (~> 1.16)
66
+ opentracing_test_tracer (~> 0.1)
67
+ rake (~> 10.0)
68
+ rest-client (= 2.0.0)
69
+ restclient-instrumentation!
70
+ rspec (~> 3.0)
71
+ webmock (~> 3.4.2)
72
+
73
+ BUNDLED WITH
74
+ 1.16.5
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "rest-client"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,74 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ restclient-instrumentation (0.1.0)
5
+ opentracing (~> 0.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ addressable (2.5.2)
11
+ public_suffix (>= 2.0.2, < 4.0)
12
+ appraisal (2.2.0)
13
+ bundler
14
+ rake
15
+ thor (>= 0.14.0)
16
+ crack (0.4.3)
17
+ safe_yaml (~> 1.0.0)
18
+ diff-lcs (1.3)
19
+ domain_name (0.5.20180417)
20
+ unf (>= 0.0.5, < 1.0.0)
21
+ hashdiff (0.3.7)
22
+ http-cookie (1.0.3)
23
+ domain_name (~> 0.5)
24
+ mime-types (3.2.2)
25
+ mime-types-data (~> 3.2015)
26
+ mime-types-data (3.2018.0812)
27
+ netrc (0.11.0)
28
+ opentracing (0.4.3)
29
+ opentracing_test_tracer (0.1.1)
30
+ opentracing
31
+ public_suffix (3.0.3)
32
+ rake (10.5.0)
33
+ rest-client (2.0.2)
34
+ http-cookie (>= 1.0.2, < 2.0)
35
+ mime-types (>= 1.16, < 4.0)
36
+ netrc (~> 0.8)
37
+ rspec (3.8.0)
38
+ rspec-core (~> 3.8.0)
39
+ rspec-expectations (~> 3.8.0)
40
+ rspec-mocks (~> 3.8.0)
41
+ rspec-core (3.8.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-expectations (3.8.2)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-mocks (3.8.0)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.8.0)
49
+ rspec-support (3.8.0)
50
+ safe_yaml (1.0.4)
51
+ thor (0.20.3)
52
+ unf (0.1.4)
53
+ unf_ext
54
+ unf_ext (0.0.7.5)
55
+ webmock (3.4.2)
56
+ addressable (>= 2.3.6)
57
+ crack (>= 0.3.2)
58
+ hashdiff
59
+
60
+ PLATFORMS
61
+ ruby
62
+
63
+ DEPENDENCIES
64
+ appraisal (~> 2.2)
65
+ bundler (~> 1.16)
66
+ opentracing_test_tracer (~> 0.1)
67
+ rake (~> 10.0)
68
+ rest-client
69
+ restclient-instrumentation!
70
+ rspec (~> 3.0)
71
+ webmock (~> 3.4.2)
72
+
73
+ BUNDLED WITH
74
+ 1.16.5
@@ -0,0 +1,70 @@
1
+ require "opentracing"
2
+ require "restclient"
3
+ require "restclient/instrumentation/version"
4
+
5
+ module RestClient
6
+ module Instrumentation
7
+ class << self
8
+
9
+ attr_accessor :tracer
10
+
11
+ def instrument(tracer: OpenTracing.global_tracer, propagate:)
12
+ @tracer = tracer
13
+
14
+ patch_request
15
+ patch_transmit if propagate
16
+ end
17
+
18
+ def patch_request
19
+
20
+ ::RestClient::Request.class_eval do
21
+ alias_method :execute_original, :execute if !self.method_defined? :execute_original
22
+
23
+ def execute(&block)
24
+ tags = {
25
+ 'span.kind' => 'client',
26
+ 'http.method' => method,
27
+ 'http.url' => url,
28
+ }
29
+
30
+ result = nil
31
+
32
+ span = ::RestClient::Instrumentation.tracer.start_span("restclient.execute", tags: tags)
33
+ begin
34
+ # make this available to the transmit method to inject the context
35
+ @span_context = span.context
36
+
37
+ result = execute_original(&block)
38
+
39
+ span.set_tag("http.status_code", result.code)
40
+ rescue => error
41
+ span.set_tag("http.status_code", error.http_code)
42
+ span.set_tag("error", true)
43
+ span.log_kv(key: "message", value: error.message)
44
+
45
+ # pass this along for the original caller to handle
46
+ raise error
47
+ ensure
48
+ span.finish()
49
+ end
50
+
51
+ result
52
+ end # execute
53
+ end # module_eval
54
+ end # patch_request
55
+
56
+ def patch_transmit
57
+ ::RestClient::Request.class_eval do
58
+
59
+ alias_method :transmit_original, :transmit if !self.method_defined? :transmit_original
60
+
61
+ def transmit(uri, req, payload, &block)
62
+ ::RestClient::Instrumentation.tracer.inject(@span_context, OpenTracing::FORMAT_RACK, req) if @span_context
63
+
64
+ transmit_original(uri, req, payload, &block)
65
+ end # transmit
66
+ end # class_eval
67
+ end # patch_transmit
68
+ end # class << self
69
+ end # module Instrumentation
70
+ end # module RestClient
@@ -0,0 +1,5 @@
1
+ module Restclient
2
+ module Instrumentation
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,34 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "restclient/instrumentation/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "restclient-instrumentation"
8
+ spec.version = Restclient::Instrumentation::VERSION
9
+ spec.authors = ["Ashwin Chandrasekar"]
10
+ spec.email = ["achandrasekar@signalfx.com"]
11
+
12
+ spec.summary = %q{Instrumentation for RestClient}
13
+ spec.description = %q{OpenTracing auto-instrumentation for RestClient.}
14
+ spec.homepage = "http://github.com/signalfx/ruby-restclient-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_dependency "opentracing", "~> 0.3"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ spec.add_development_dependency "webmock", "~> 3.4.2"
33
+ spec.add_development_dependency "appraisal", "~> 2.2"
34
+ end
metadata ADDED
@@ -0,0 +1,157 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: restclient-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: 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: opentracing_test_tracer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.4.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: appraisal
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '2.2'
111
+ description: OpenTracing auto-instrumentation for RestClient.
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
+ - gemfiles/rest_client_2.0.0.gemfile
127
+ - gemfiles/rest_client_2.0.0.gemfile.lock
128
+ - gemfiles/rest_client_latest.gemfile
129
+ - gemfiles/rest_client_latest.gemfile.lock
130
+ - lib/restclient/instrumentation.rb
131
+ - lib/restclient/instrumentation/version.rb
132
+ - restclient-instrumentation.gemspec
133
+ homepage: http://github.com/signalfx/ruby-restclient-instrumentation
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.6.13
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: Instrumentation for RestClient
157
+ test_files: []