ygrene_istio_tracing 1.0.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
+ SHA256:
3
+ metadata.gz: 667117a1dbd6ed934cab51547d6d9577fcea2099906d1813fc0dbf743a1d872d
4
+ data.tar.gz: 8bfa727b291c112b1c634110d713fc852dd61056db82f8ef390b974b69cc1fd9
5
+ SHA512:
6
+ metadata.gz: 88d7f68cf1025ffe4626b60353a3ae98167a9936a829f2447309c2bc3a772f9e0528ce57e783ef12c086b399f8a446c0d66f871a0184af859626721c283135c9
7
+ data.tar.gz: a5ad51f752f35faaeec3f41e32d3334c9b942be07dca72b52c3f851b8738159bc34b4ef1f60a37d2bfa2c57db4cfb750d076d1ddc99964358146cb50e708d5d0
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in istio.gemspec
8
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,116 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ygrene_istio_tracing (1.0.0)
5
+ typhoeus (~> 1.3.1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (5.2.2)
11
+ actionview (= 5.2.2)
12
+ activesupport (= 5.2.2)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
17
+ actionview (5.2.2)
18
+ activesupport (= 5.2.2)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
23
+ activesupport (5.2.2)
24
+ concurrent-ruby (~> 1.0, >= 1.0.2)
25
+ i18n (>= 0.7, < 2)
26
+ minitest (~> 5.1)
27
+ tzinfo (~> 1.1)
28
+ addressable (2.5.2)
29
+ public_suffix (>= 2.0.2, < 4.0)
30
+ builder (3.2.3)
31
+ concurrent-ruby (1.1.3)
32
+ crack (0.4.3)
33
+ safe_yaml (~> 1.0.0)
34
+ crass (1.0.4)
35
+ diff-lcs (1.3)
36
+ erubi (1.7.1)
37
+ ethon (0.11.0)
38
+ ffi (>= 1.3.0)
39
+ ffi (1.9.25)
40
+ hashdiff (0.3.7)
41
+ httparty (0.16.3)
42
+ mime-types (~> 3.0)
43
+ multi_xml (>= 0.5.2)
44
+ i18n (1.2.0)
45
+ concurrent-ruby (~> 1.0)
46
+ loofah (2.2.3)
47
+ crass (~> 1.0.2)
48
+ nokogiri (>= 1.5.9)
49
+ method_source (0.9.2)
50
+ mime-types (3.2.2)
51
+ mime-types-data (~> 3.2015)
52
+ mime-types-data (3.2018.0812)
53
+ mini_portile2 (2.3.0)
54
+ minitest (5.11.3)
55
+ multi_xml (0.6.0)
56
+ nokogiri (1.8.5)
57
+ mini_portile2 (~> 2.3.0)
58
+ public_suffix (3.0.3)
59
+ rack (2.0.6)
60
+ rack-test (1.1.0)
61
+ rack (>= 1.0, < 3)
62
+ rails-dom-testing (2.0.3)
63
+ activesupport (>= 4.2.0)
64
+ nokogiri (>= 1.6)
65
+ rails-html-sanitizer (1.0.4)
66
+ loofah (~> 2.2, >= 2.2.2)
67
+ railties (5.2.2)
68
+ actionpack (= 5.2.2)
69
+ activesupport (= 5.2.2)
70
+ method_source
71
+ rake (>= 0.8.7)
72
+ thor (>= 0.19.0, < 2.0)
73
+ rake (10.5.0)
74
+ rspec-core (3.8.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-expectations (3.8.2)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-mocks (3.8.0)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.8.0)
82
+ rspec-rails (3.8.1)
83
+ actionpack (>= 3.0)
84
+ activesupport (>= 3.0)
85
+ railties (>= 3.0)
86
+ rspec-core (~> 3.8.0)
87
+ rspec-expectations (~> 3.8.0)
88
+ rspec-mocks (~> 3.8.0)
89
+ rspec-support (~> 3.8.0)
90
+ rspec-support (3.8.0)
91
+ safe_yaml (1.0.4)
92
+ thor (0.20.3)
93
+ thread_safe (0.3.6)
94
+ typhoeus (1.3.1)
95
+ ethon (>= 0.9.0)
96
+ tzinfo (1.2.5)
97
+ thread_safe (~> 0.1)
98
+ webmock (3.3.0)
99
+ addressable (>= 2.3.6)
100
+ crack (>= 0.3.2)
101
+ hashdiff
102
+
103
+ PLATFORMS
104
+ ruby
105
+
106
+ DEPENDENCIES
107
+ bundler (~> 1.16)
108
+ httparty (~> 0.16.3)
109
+ rack
110
+ rake (~> 10.0)
111
+ rspec-rails
112
+ webmock (~> 3.3.0)
113
+ ygrene_istio_tracing!
114
+
115
+ BUNDLED WITH
116
+ 1.16.6
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Wantedly, Inc., Ygrene Energy Fund
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # Ygrene Istio Tracing Gem
2
+
3
+ Rails instrumentation gem for Istio service mesh (https://istio.io/).
4
+
5
+ This gem lets your Rails services propagate b3 http headers for distributed tracing with Istio.
6
+ It propigates headers to Net::Http and Typhoeus(uses libcurl)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'ygrene_istio_tracing'
14
+ ```
15
+ ## Usage
16
+
17
+ Installed into the rails-setup gem for ygrene usage.
18
+
19
+ ## Development
20
+
21
+ 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.
22
+
23
+ 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).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'istio'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ 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
data/istio.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'istio/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ygrene_istio_tracing'
9
+ spec.version = Istio::VERSION
10
+ spec.authors = ['Austin Adams']
11
+ spec.email = ['me@austbot.com']
12
+
13
+ spec.summary = 'Ruby gem for Istio service mesh (https://istio.io/)'
14
+ spec.description = 'This gem lets your rails app propagate http headers for distributed tracing with Istio.'
15
+ spec.homepage = 'https://github.com/ygrene/ygrene-istio-tracing'
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
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = 'exe'
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ['lib']
34
+
35
+ spec.add_dependency 'typhoeus', '~> 1.3.1'
36
+
37
+ spec.add_development_dependency 'bundler', '~> 1.16'
38
+ spec.add_development_dependency 'rack'
39
+ spec.add_development_dependency 'rake', '~> 10.0'
40
+ spec.add_development_dependency 'rspec-rails'
41
+
42
+ spec.add_development_dependency 'webmock', ['~>3.3.0']
43
+ spec.add_development_dependency 'httparty', ['~>0.16.3']
44
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Istio
4
+ module Tracing
5
+ class NotSetError < ::StandardError
6
+ def initialize
7
+ super('Context is not set for this thread')
8
+ end
9
+ end
10
+
11
+ class Context
12
+ VAR_NAME = :_istio_tracing_context_
13
+
14
+ class << self
15
+ def current
16
+ Thread.current.thread_variable_get(VAR_NAME) || raise(NotSetError)
17
+ end
18
+
19
+ def with_given_context(ctx)
20
+ Thread.current.thread_variable_set(VAR_NAME, ctx)
21
+ yield
22
+ ensure
23
+ remove_current
24
+ end
25
+
26
+ def exists_current?
27
+ !!Thread.current.thread_variable_get(VAR_NAME)
28
+ end
29
+
30
+ def build_current(headers)
31
+ Thread.current.thread_variable_set(VAR_NAME, Context.new(headers))
32
+ end
33
+
34
+ def remove_current
35
+ Thread.current.thread_variable_set(VAR_NAME, nil)
36
+ end
37
+ end
38
+
39
+ attr_reader :headers
40
+
41
+ def initialize(headers)
42
+ @headers = headers
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Istio
4
+ module Tracing
5
+ PROPAGATION_HEADERS = %w[
6
+ x-request-id
7
+ x-b3-traceid
8
+ x-b3-spanid
9
+ x-b3-parentspanid
10
+ x-b3-sampled
11
+ x-b3-flags
12
+ x-ot-span-context
13
+ X-REQUEST-ID
14
+ X-B3-TRACEID
15
+ X-B3-SPANID
16
+ X-B3-PARENTSPANID
17
+ X-B3-SAMPLED
18
+ X-B3-FLAGS
19
+ X-OT-SPAN-CONTEXT
20
+ ].freeze
21
+ end
22
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+ require 'typhoeus'
5
+
6
+ module Istio
7
+ module NetHttp
8
+ module ClassInterceptor
9
+ def new(*options)
10
+ o = super(*options)
11
+ o
12
+ end
13
+ end
14
+ module InstanceInterceptor
15
+ def initialize(*options)
16
+ super(*options)
17
+ end
18
+
19
+ def request(req, *args, &block)
20
+ return super unless Context.exists_current?
21
+
22
+ headers = Context.current.headers
23
+ PROPAGATION_HEADERS.each do |h|
24
+ req[h] = headers[h] if headers[h].present?
25
+ end
26
+ super
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ ::Net::HTTP.singleton_class.prepend Istio::NetHttp::ClassInterceptor
33
+ ::Net::HTTP.prepend Istio::NetHttp::InstanceInterceptor
34
+
35
+ module Typhoeus
36
+ Typhoeus.before do |req|
37
+ return req unless Istio::Tracing::Context.exists_current?
38
+
39
+ headers = Istio::Tracing::Context.current.headers
40
+ Istio::Tracing::PROPAGATION_HEADERS.each do |h|
41
+ req.options[:headers][h] = headers[h] unless headers[h]&.nil?
42
+ end
43
+ req
44
+ end
45
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Istio
4
+ module Tracing
5
+ class RackMiddleware
6
+
7
+ def initialize(app)
8
+ @app = app
9
+ end
10
+
11
+ def call(env)
12
+ Context.build_current(extract_http_headers(env))
13
+ @app.call(env)
14
+ ensure
15
+ Context.remove_current
16
+ end
17
+
18
+ def extract_http_headers(env)
19
+ env.select { |k, _v| PROPAGATION_HEADERS.include?(k.downcase) }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module Istio
6
+ module Tracing
7
+ class Railtie < ::Rails::Railtie
8
+ initializer 'istio.tracing.rack_middleware' do |app|
9
+ app.middleware.use(::Istio::Tracing::RackMiddleware)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'istio/tracing/context'
4
+ require 'istio/tracing/header'
5
+ require 'istio/tracing/http'
6
+ require 'istio/tracing/rack'
7
+
8
+ begin
9
+ require 'rails/railtie'
10
+ require 'istio/tracing/railtie'
11
+ rescue LoadError
12
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Istio
4
+ VERSION = '1.0.0'
5
+ end
data/lib/istio.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'istio/version'
4
+ require 'istio/tracing'
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ygrene_istio_tracing
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Austin Adams
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.3.1
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: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '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'
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.3.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.3.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: httparty
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.16.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.16.3
111
+ description: This gem lets your rails app propagate http headers for distributed tracing
112
+ with Istio.
113
+ email:
114
+ - me@austbot.com
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - ".rspec"
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - LICENSE
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/setup
128
+ - istio.gemspec
129
+ - lib/istio.rb
130
+ - lib/istio/tracing.rb
131
+ - lib/istio/tracing/context.rb
132
+ - lib/istio/tracing/header.rb
133
+ - lib/istio/tracing/http.rb
134
+ - lib/istio/tracing/rack.rb
135
+ - lib/istio/tracing/railtie.rb
136
+ - lib/istio/version.rb
137
+ homepage: https://github.com/ygrene/ygrene-istio-tracing
138
+ licenses: []
139
+ metadata:
140
+ allowed_push_host: https://rubygems.org
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.7.8
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Ruby gem for Istio service mesh (https://istio.io/)
161
+ test_files: []