zipkin-tracer 0.20.1 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 875a585c719b81da5b6ec5e7e6aff0f81b3ec9d1
4
- data.tar.gz: f893dc0e63cc5a17aeade2b290378344ef28ec63
3
+ metadata.gz: e002f70c008b6d4adb6dde3eb8889ca235734c90
4
+ data.tar.gz: 200e21061d741afec8bee82ac70c64161296b29f
5
5
  SHA512:
6
- metadata.gz: adef43d068c3cc6c936d6b22f9c1997ec6efdf82f2fcf50b4f36c447aa2b4aa995d6ed220b88a654b5f4043b1d37a9a5d4092b0286074c941ce07e205c279e59
7
- data.tar.gz: 4e5cc0ecb720484865284897a760a3ce25cbd83d27d0f0b241fc9515ed1864aa92115cca6b671dc02ac3b2779ecfbab76b73dc2179263767ca5d6d0985277926
6
+ metadata.gz: bda12147fb3da63f9c084e2cd5296c17eefdb7f5c772556cd9279b88958e8ff1e703d025eed9be11a26221882decf350e9e1d78e3dbd2afd87d1b3374ae708c3
7
+ data.tar.gz: 96bf6c9f089226c241f0ad53817826bfb6983d9792594dec392ae1ff02ade9befca66807723fca937f12984640d3ae4218b5e25017484f9331738d69b6856948
@@ -10,3 +10,9 @@ begin
10
10
  require 'zipkin-tracer/faraday/zipkin-tracer'
11
11
  rescue LoadError #Faraday is not available, we do not load our code.
12
12
  end
13
+
14
+ begin
15
+ require 'excon'
16
+ require 'zipkin-tracer/excon/zipkin-tracer'
17
+ rescue LoadError
18
+ end
@@ -0,0 +1,85 @@
1
+ require 'finagle-thrift/trace'
2
+ require 'finagle-thrift/tracer'
3
+ require 'uri'
4
+ require 'excon'
5
+
6
+ module ZipkinTracer
7
+ class ExconHandler < Excon::Middleware::Base
8
+ def initialize(_)
9
+ super
10
+ end
11
+
12
+ def error_call(datum)
13
+ super(datum)
14
+ end
15
+
16
+ def request_call(datum)
17
+ trace_id = TraceGenerator.new.next_trace_id
18
+
19
+ TraceContainer.with_trace_id(trace_id) do
20
+ b3_headers.each do |method, header|
21
+ datum[:headers][header] = trace_id.send(method).to_s
22
+ end
23
+
24
+ trace!(datum, trace_id) if trace_id.sampled?
25
+ end
26
+
27
+ super(datum)
28
+ end
29
+
30
+ def response_call(datum)
31
+ response = datum[:response]
32
+
33
+ if span = datum[:span]
34
+ span.record_tag(Trace::BinaryAnnotation::STATUS, response[:status].to_s, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
35
+ span.record(Trace::Annotation::CLIENT_RECV, local_endpoint)
36
+ end
37
+
38
+ super(datum)
39
+ end
40
+
41
+ private
42
+
43
+ SERVER_ADDRESS_SPECIAL_VALUE = '1'.freeze
44
+
45
+ def b3_headers
46
+ {
47
+ trace_id: 'X-B3-TraceId',
48
+ parent_id: 'X-B3-ParentSpanId',
49
+ span_id: 'X-B3-SpanId',
50
+ sampled: 'X-B3-Sampled',
51
+ flags: 'X-B3-Flags'
52
+ }
53
+ end
54
+
55
+ def local_endpoint
56
+ Trace.default_endpoint # The rack middleware set this up for us.
57
+ end
58
+
59
+ def remote_endpoint(url, service_name)
60
+ Trace::Endpoint.remote_endpoint(url, service_name, local_endpoint.ip_format) # The endpoint we are calling.
61
+ end
62
+
63
+ def service_name(datum, default)
64
+ datum.fetch(:zipkin_service_name, default)
65
+ end
66
+
67
+ def trace!(datum, trace_id)
68
+ url_string = Excon::Utils::request_uri(datum)
69
+ url = URI(url_string)
70
+ service_name = service_name(datum, url.host)
71
+
72
+ Trace.tracer.with_new_span(trace_id, datum[:method].to_s.downcase) do |span|
73
+ # annotate with method (GET/POST/etc.) and uri path
74
+ span.record_tag(Trace::BinaryAnnotation::PATH, url.path, Trace::BinaryAnnotation::Type::STRING, local_endpoint)
75
+ span.record_tag(Trace::BinaryAnnotation::SERVER_ADDRESS, SERVER_ADDRESS_SPECIAL_VALUE, Trace::BinaryAnnotation::Type::BOOL, remote_endpoint(url, service_name))
76
+ span.record(Trace::Annotation::CLIENT_SEND, local_endpoint)
77
+
78
+ # store the span in the datum hash so it can be used in the response_call
79
+ datum[:span] = span
80
+ end
81
+ rescue ArgumentError, URI::Error => e
82
+ # Ignore URI errors, don't trace if there is no URI
83
+ end
84
+ end
85
+ end
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.20.1'.freeze
2
+ VERSION = '0.21.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zipkin-tracer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.1
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Franklin Hu
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2016-12-28 00:00:00.000000000 Z
16
+ date: 2017-03-09 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: faraday
@@ -71,6 +71,20 @@ dependencies:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
73
  version: '2.0'
74
+ - !ruby/object:Gem::Dependency
75
+ name: excon
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '0.53'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '0.53'
74
88
  - !ruby/object:Gem::Dependency
75
89
  name: rspec
76
90
  requirement: !ruby/object:Gem::Requirement
@@ -156,6 +170,7 @@ files:
156
170
  - lib/zipkin-tracer.rb
157
171
  - lib/zipkin-tracer/application.rb
158
172
  - lib/zipkin-tracer/config.rb
173
+ - lib/zipkin-tracer/excon/zipkin-tracer.rb
159
174
  - lib/zipkin-tracer/faraday/zipkin-tracer.rb
160
175
  - lib/zipkin-tracer/hostname_resolver.rb
161
176
  - lib/zipkin-tracer/rack/zipkin-tracer.rb