ygrene_istio_tracing 1.0.2 → 1.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8361cbf8ec454a057b43180a718ba352d20a83658b36cd4efd92a24320ca853e
4
- data.tar.gz: a052baad266616035ece1adbbb4d2c2fd6c4950c8cf379b47c92e4cbd7afef88
3
+ metadata.gz: 130a10777cc833fd87deccd676ec488a8b851fd9e875603e8aca682355ecf29a
4
+ data.tar.gz: ce364a10d73bc0008010cdd6b848e4759e793a5e1fa3423ca39d2b9169cd7a24
5
5
  SHA512:
6
- metadata.gz: dd6558df91d5c1c8f69ea7e71d9da9f01bd4dc5548f23cca204a15f6b86ab456d49ccf9abdffa90120161d7902c346da8e3e4d5cb9eb0722a2f293c12c182854
7
- data.tar.gz: 5b4cc52c8e68f37e5c4e2bf00fe10f3b661df4c70eefaae4da92247d8b7afb68d2a37e947030c457028e305251d4c448c539c15409e64b52b482aa5aa0d182ac
6
+ metadata.gz: a86ed190b5a3556d02dba560899e723856e950fdb3079ce0662502a3f86e41cd7e23726ad402120bf17b9cfaeafaa02871710325fd12c6b982d2ce5de8a8ed7b
7
+ data.tar.gz: 34e5a7cc8bffff5b33985f9d426a5cfb1b510448859f35f3abe13a3ca1f5694f1943c45f5c5085ccfa80935036f1f92bdf8d86e3449b71b0c8385624fa8d775a
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ygrene-istio-tracing
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.5.1
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ygrene_istio_tracing/version'
4
+ require 'ygrene_istio_tracing/tracing'
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ygrene_istio_tracing/tracing/context'
4
+ require 'ygrene_istio_tracing/tracing/header'
5
+ require 'ygrene_istio_tracing/tracing/http'
6
+ require 'ygrene_istio_tracing/tracing/rack'
7
+
8
+ begin
9
+ require 'rails/railtie'
10
+ require 'ygrene_istio_tracing/tracing/railtie'
11
+ rescue LoadError
12
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YgreneIstioTracing
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 YgreneIstioTracing
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 YgreneIstioTracing
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 = YgreneIstioTracing::Tracing::Context.current.headers
23
+ YgreneIstioTracing::Tracing::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 YgreneIstioTracing::NetHttp::ClassInterceptor
33
+ ::Net::HTTP.prepend YgreneIstioTracing::NetHttp::InstanceInterceptor
34
+
35
+ module Typhoeus
36
+ Typhoeus.before do |req|
37
+ return req unless YgreneIstioTracing::Tracing::Context.exists_current?
38
+
39
+ headers = YgreneIstioTracing::Tracing::Context.current.headers
40
+ YgreneIstioTracing::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 YgreneIstioTracing
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,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module YgreneIstioTracing
6
+ module Tracing
7
+ class Railtie < ::Rails::Railtie
8
+ initializer 'ygrene_istio_tracing.tracing.rack_middleware' do |app|
9
+ puts 'Tracing Loaded'
10
+ app.middleware.use(::Istio::Tracing::RackMiddleware)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module YgreneIstioTracing
4
+ VERSION = '1.0.3'
5
+ end
@@ -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 'ygrene_istio_tracing/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'ygrene_istio_tracing'
9
+ spec.version = YgreneIstioTracing::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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ygrene_istio_tracing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Austin Adams
@@ -118,6 +118,8 @@ extra_rdoc_files: []
118
118
  files:
119
119
  - ".gitignore"
120
120
  - ".rspec"
121
+ - ".ruby-gemset"
122
+ - ".ruby-version"
121
123
  - Gemfile
122
124
  - Gemfile.lock
123
125
  - LICENSE
@@ -125,6 +127,15 @@ files:
125
127
  - Rakefile
126
128
  - bin/console
127
129
  - bin/setup
130
+ - lib/ygrene_istio_tracing.rb
131
+ - lib/ygrene_istio_tracing/tracing.rb
132
+ - lib/ygrene_istio_tracing/tracing/context.rb
133
+ - lib/ygrene_istio_tracing/tracing/header.rb
134
+ - lib/ygrene_istio_tracing/tracing/http.rb
135
+ - lib/ygrene_istio_tracing/tracing/rack.rb
136
+ - lib/ygrene_istio_tracing/tracing/railtie.rb
137
+ - lib/ygrene_istio_tracing/version.rb
138
+ - ygrene_istio_tracing.gemspec
128
139
  homepage: https://github.com/ygrene/ygrene_istio_tracing
129
140
  licenses: []
130
141
  metadata: