httprb-opentracing 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: 3a402047a11ea48f47ccdc2b0ad5c15bcd2e2b2c
4
+ data.tar.gz: 07e4acf0d06b22952a05ea252b5a0bb0b279f148
5
+ SHA512:
6
+ metadata.gz: 5a5932e89e67034612dfa45b0e1fe828fbffd933e82642605f0b8f8b0f835ab3537d8d0517d79833bc7c543ef64f7e29205e5105ac20ac41fc5110cdd4375fae
7
+ data.tar.gz: aefcb10500fb23cb1e4dff049cd387d63de8e7b267f053cbbed2c7c9feee5ffc0069ac0222535d8d7e7f7de9dd8ea6b5a61e9ca4955e0ed84bb815057e12fd05
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.3.7
7
+ before_install: gem install bundler -v 2.0.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ Changelog
2
+ =========
3
+
4
+ ## 0.1.0 08/01/2019
5
+ * Instrumention for open tracing using the HTTP client request api
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ben.fischer.810@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ httprb-opentracing (0.1.0)
5
+ http (> 0.1.0)
6
+ opentracing (~> 0.5.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.6.0)
12
+ public_suffix (>= 2.0.2, < 4.0)
13
+ byebug (11.0.1)
14
+ crack (0.4.3)
15
+ safe_yaml (~> 1.0.0)
16
+ diff-lcs (1.3)
17
+ domain_name (0.5.20190701)
18
+ unf (>= 0.0.5, < 1.0.0)
19
+ hashdiff (1.0.0)
20
+ http (2.2.3.doxpre1)
21
+ addressable (~> 2.3)
22
+ http-cookie (~> 1.0)
23
+ http-form_data (~> 1.0.1)
24
+ http_parser.rb (~> 0.6.0)
25
+ http-cookie (1.0.3)
26
+ domain_name (~> 0.5)
27
+ http-form_data (1.0.3)
28
+ http_parser.rb (0.6.0)
29
+ opentracing (0.5.0)
30
+ opentracing_test_tracer (0.1.1)
31
+ opentracing
32
+ public_suffix (3.1.1)
33
+ rake (10.5.0)
34
+ rspec (3.8.0)
35
+ rspec-core (~> 3.8.0)
36
+ rspec-expectations (~> 3.8.0)
37
+ rspec-mocks (~> 3.8.0)
38
+ rspec-core (3.8.2)
39
+ rspec-support (~> 3.8.0)
40
+ rspec-expectations (3.8.4)
41
+ diff-lcs (>= 1.2.0, < 2.0)
42
+ rspec-support (~> 3.8.0)
43
+ rspec-mocks (3.8.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.8.0)
46
+ rspec-support (3.8.2)
47
+ safe_yaml (1.0.5)
48
+ unf (0.1.4)
49
+ unf_ext
50
+ unf_ext (0.0.7.6)
51
+ webmock (3.4.2)
52
+ addressable (>= 2.3.6)
53
+ crack (>= 0.3.2)
54
+ hashdiff
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ bundler (~> 2.0)
61
+ byebug
62
+ httprb-opentracing!
63
+ opentracing_test_tracer (~> 0.1)
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+ webmock (~> 3.4.2)
67
+
68
+ BUNDLED WITH
69
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ben Fischer
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,54 @@
1
+ # HTTP Opentracing
2
+
3
+ Open Tracing instrumentation for the [http gem](https://github.com/httprb/http). By default it starts a new span for every request and follows the open tracing tagging [semantic conventions](https://opentracing.io/specification/conventions)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'httprb-opentracing'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install httprb-opentracing
20
+
21
+ ## Usage
22
+ First load the instrumentation (Note: this won't automatically instrument the http gem)
23
+ ```
24
+ require "httprb-opentracing"
25
+ ```
26
+
27
+ If you have setup `OpenTracing.global_tracer` you can turn on spans for all requests with just:
28
+ ```
29
+ HTTP::Tracer.instrument
30
+ ```
31
+
32
+ If you need more control over the tracer or which requests get their own span you can configure both settings like:
33
+ ```
34
+ HTTP::Tracer.instrument(
35
+ tracer: tracer,
36
+ ignore_request: ->(verb, uri, opts) { uri.host == 'localhost' }
37
+ )
38
+ ```
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rspec` to run the tests.
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/benedictfischer09/ruby-httprb-instrumentation. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
+
48
+ ## License
49
+
50
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
51
+
52
+ ## Code of Conduct
53
+
54
+ Everyone interacting in the project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/benedictfischer09/ruby-httprb-instrumentation/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "http/tracer"
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,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'http/tracer/version'
4
+ require 'opentracing'
5
+
6
+ module HTTP
7
+ module Tracer
8
+ class << self
9
+ attr_accessor :ignore_request, :tracer
10
+
11
+ IngoreRequest = ->(_verb, _uri, _opts) { false }
12
+
13
+ def instrument(tracer: OpenTracing.global_tracer, ignore_request: IngoreRequest)
14
+ @ignore_request = ignore_request
15
+ @tracer = tracer
16
+ patch_request
17
+ end
18
+
19
+ def remove
20
+ return unless ::HTTP::Client.method_defined?(:request_original)
21
+
22
+ ::HTTP::Client.class_eval do
23
+ remove_method :request
24
+ alias_method :request, :request_original
25
+ remove_method :request_original
26
+ end
27
+ end
28
+
29
+ def patch_request
30
+ ::HTTP::Client.class_eval do
31
+ alias_method :request_original, :request
32
+
33
+ def request(verb, uri, opts = {})
34
+ options = HTTP::Options.new.merge(opts)
35
+ parsed_uri = uri.is_a?(String) ? URI(uri) : uri
36
+
37
+ if ::HTTP::Tracer.ignore_request.call(verb, uri, options)
38
+ res = request_original(verb, uri, options)
39
+ else
40
+ tags = {
41
+ 'component' => 'ruby-httprb',
42
+ 'span.kind' => 'client',
43
+ 'http.method' => verb,
44
+ 'http.url' => parsed_uri.path,
45
+ 'peer.host' => parsed_uri.host,
46
+ 'peer.port' => parsed_uri.port
47
+ }
48
+
49
+ tracer = ::HTTP::Tracer.tracer
50
+
51
+ tracer.start_active_span('http.request', tags: tags) do |scope|
52
+ OpenTracing.inject(scope.span.context, OpenTracing::FORMAT_RACK, options.headers)
53
+
54
+ res = request_original(verb, uri, options)
55
+
56
+ scope.span.set_tag('http.status_code', res.status)
57
+ scope.span.set_tag('error', true) if res.is_a?(StandardError)
58
+ end
59
+ end
60
+
61
+ res
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HTTP
4
+ module Tracer
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1 @@
1
+ require "http/tracer"
@@ -0,0 +1,47 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "http/tracer/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "httprb-opentracing"
8
+ spec.version = HTTP::Tracer::VERSION
9
+ spec.authors = ["Ben Fischer"]
10
+ spec.email = ["ben.fischer.810@gmail.com"]
11
+
12
+ spec.summary = %q{Instruments the http gem for distributed tracing}
13
+ spec.description = %q{Instruments the http gem for distributed tracing}
14
+ spec.homepage = "https://github.com/benedictfischer09/ruby-httprb-instrumentation"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/benedictfischer09/ruby-httprb-instrumentation"
24
+ spec.metadata["changelog_uri"] = "https://github.com/benedictfischer09/ruby-httprb-instrumentation/blob/master/CHANGELOG"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "opentracing", "~> 0.5.0"
40
+ spec.add_dependency "http", "> 0.1.0"
41
+ spec.add_development_dependency "bundler", "~> 2.0"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ spec.add_development_dependency "opentracing_test_tracer", "~> 0.1"
45
+ spec.add_development_dependency "webmock", "~> 3.4.2"
46
+ spec.add_development_dependency "byebug"
47
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: httprb-opentracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ben Fischer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-16 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.5.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
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: 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: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.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: 3.4.2
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Instruments the http gem for distributed tracing
126
+ email:
127
+ - ben.fischer.810@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - CHANGELOG.md
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - Gemfile.lock
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - bin/console
143
+ - bin/setup
144
+ - lib/http/tracer.rb
145
+ - lib/http/tracer/version.rb
146
+ - lib/httprb-opentracing.rb
147
+ - ruby-httprb-instrumentation.gemspec
148
+ homepage: https://github.com/benedictfischer09/ruby-httprb-instrumentation
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ allowed_push_host: https://rubygems.org
153
+ homepage_uri: https://github.com/benedictfischer09/ruby-httprb-instrumentation
154
+ source_code_uri: https://github.com/benedictfischer09/ruby-httprb-instrumentation
155
+ changelog_uri: https://github.com/benedictfischer09/ruby-httprb-instrumentation/blob/master/CHANGELOG
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.5.2.3
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Instruments the http gem for distributed tracing
176
+ test_files: []