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 +4 -4
- data/lib/zipkin-tracer.rb +6 -0
- data/lib/zipkin-tracer/excon/zipkin-tracer.rb +85 -0
- data/lib/zipkin-tracer/version.rb +1 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e002f70c008b6d4adb6dde3eb8889ca235734c90
|
4
|
+
data.tar.gz: 200e21061d741afec8bee82ac70c64161296b29f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda12147fb3da63f9c084e2cd5296c17eefdb7f5c772556cd9279b88958e8ff1e703d025eed9be11a26221882decf350e9e1d78e3dbd2afd87d1b3374ae708c3
|
7
|
+
data.tar.gz: 96bf6c9f089226c241f0ad53817826bfb6983d9792594dec392ae1ff02ade9befca66807723fca937f12984640d3ae4218b5e25017484f9331738d69b6856948
|
data/lib/zipkin-tracer.rb
CHANGED
@@ -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
|
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.
|
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:
|
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
|