zipkin-tracer 0.14.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/zipkin-tracer/hostname_resolver.rb +63 -0
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +6 -19
- data/lib/zipkin-tracer/trace.rb +3 -11
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/zipkin_json_tracer.rb +3 -1
- data/lib/zipkin-tracer/zipkin_kafka_tracer.rb +3 -1
- data/lib/zipkin-tracer/zipkin_logger_tracer.rb +3 -1
- data/lib/zipkin-tracer/zipkin_scribe_tracer.rb +4 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmU1ZjgyYTNmNWYzZDQ3N2VjMTFiMGYwZDA1ZmRkZWY5NWE1YTc3Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTNhNDM3NTU0ZTAzMTgxZGFhN2I3NmIzODYyZThkYTFmNGEzMmE4Nw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OTFmOTc1NDAxZGM3NWE0MDUxNWVmZjVmNzlkZDY2N2FlMTU0ZWIwOGZkMzFl
|
10
|
+
NzJiODJiNGNkMWFkNDJjN2YzZDJkODUyZTA0MDQ1MDYxNjdjMDA4MTFhZWNl
|
11
|
+
NjgxYjRiYjc3YzZkODRlZDJiNThkZTFlODE3MTIxMWFmOGY1NGQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGI0NjFkODBiMzRhZDBmMTc2M2ViYzBmOWFkMGEyNmE1YTU4MTU2MDA2MGU0
|
14
|
+
Njc4NjRmMDNjMTBhNGMwZWRiMmI2NmIxNzcwMjAxMGU3YWYzNGZjYmFiOTZi
|
15
|
+
ZDQzYjRkMjQ3ZTU3Nzc0OGVmNzUxY2ViZTIyZDE3NGRjYTRhYmU=
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module ZipkinTracer
|
2
|
+
# Resolves hostnames in the endpoints of the annotations.
|
3
|
+
# Resolving hostnames is a very expensive operation. We want to store them raw in the main thread
|
4
|
+
# and resolve them in a different thread where we do not affect execution times.
|
5
|
+
class HostnameResolver
|
6
|
+
def spans_with_ips(spans)
|
7
|
+
host_to_ip = hosts_to_ipv4(spans)
|
8
|
+
|
9
|
+
each_annotation(spans) do |annotation|
|
10
|
+
hostname = annotation.host.ipv4
|
11
|
+
if hostname.to_s =~ /\A[a-zA-Z]/ # hostnames start with letters, else we already have an IP
|
12
|
+
annotation.host.ipv4 = host_to_ip[hostname]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
LOCALHOST = '127.0.0.1'.freeze
|
19
|
+
LOCALHOST_I32 = 0x7f000001.freeze
|
20
|
+
IP_FIELD = 3
|
21
|
+
|
22
|
+
def each_annotation(spans, &block)
|
23
|
+
spans.each do |span|
|
24
|
+
span.annotations.each do |annotation|
|
25
|
+
yield annotation
|
26
|
+
end
|
27
|
+
span.binary_annotations.each do |annotation|
|
28
|
+
yield annotation
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Annotations come in pairs like CS/CR, SS/SR.
|
34
|
+
# Each annnotation has a hostname so we, for sure, will have the same host multiple times.
|
35
|
+
# Using this to resolve only once per host
|
36
|
+
def hosts_to_ipv4(spans)
|
37
|
+
hosts = []
|
38
|
+
each_annotation(spans) do |annotation|
|
39
|
+
hosts.push(annotation.host)
|
40
|
+
end
|
41
|
+
hosts.uniq!
|
42
|
+
resolve(hosts)
|
43
|
+
end
|
44
|
+
|
45
|
+
def resolve(hosts)
|
46
|
+
hosts.inject({}) do |host_map, host|
|
47
|
+
hostname = host.ipv4 # This field has been temporarly used to store the hostname.
|
48
|
+
ip_format = host.ip_format
|
49
|
+
host_map[hostname] = host_to_ip(hostname, ip_format)
|
50
|
+
host_map
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def host_to_ip(hostname, ip_format)
|
55
|
+
ipv4 = begin
|
56
|
+
ip_format == :string ? Socket.getaddrinfo(hostname, nil, :INET).first[IP_FIELD] : Trace::Endpoint.host_to_i32(hostname)
|
57
|
+
rescue
|
58
|
+
ip_format == :string ? LOCALHOST : LOCALHOST_I32
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -26,7 +26,6 @@ module ZipkinTracer
|
|
26
26
|
|
27
27
|
def initialize(app, config = nil)
|
28
28
|
@app = app
|
29
|
-
@lock = Mutex.new
|
30
29
|
@config = Config.new(app, config).freeze
|
31
30
|
@tracer = TracerFactory.new.tracer(@config)
|
32
31
|
end
|
@@ -52,32 +51,20 @@ module ZipkinTracer
|
|
52
51
|
end
|
53
52
|
|
54
53
|
def trace!(span, zipkin_env, &block)
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
span.record('whitelisted') if zipkin_env.force_sample?
|
60
|
-
end
|
54
|
+
#if called by a service, the caller already added the information
|
55
|
+
trace_request_information(span, zipkin_env.env) unless zipkin_env.called_with_zipkin_headers?
|
56
|
+
span.record(Trace::Annotation::SERVER_RECV)
|
57
|
+
span.record('whitelisted') if zipkin_env.force_sample?
|
61
58
|
status, headers, body = yield
|
62
59
|
ensure
|
63
|
-
|
64
|
-
|
65
|
-
span.record(Trace::Annotation::SERVER_SEND)
|
66
|
-
end
|
60
|
+
annotate_plugin(zipkin_env.env, status, headers, body)
|
61
|
+
span.record(Trace::Annotation::SERVER_SEND)
|
67
62
|
end
|
68
63
|
|
69
64
|
def trace_request_information(span, env)
|
70
65
|
span.record_tag(Trace::BinaryAnnotation::URI, env['PATH_INFO'])
|
71
66
|
end
|
72
67
|
|
73
|
-
def synchronize(&block)
|
74
|
-
@lock.synchronize do
|
75
|
-
yield
|
76
|
-
end
|
77
|
-
rescue => e
|
78
|
-
@config.logger.error("Exception #{e.message} while sending Zipkin traces. #{e.backtrace}")
|
79
|
-
end
|
80
|
-
|
81
68
|
# Environment with Zipkin information in it
|
82
69
|
class ZipkinEnv
|
83
70
|
attr_reader :env
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -38,8 +38,8 @@ module Trace
|
|
38
38
|
traceId: @span_id.trace_id.to_s,
|
39
39
|
id: @span_id.span_id.to_s,
|
40
40
|
parentId: @span_id.parent_id.nil? ? nil : @span_id.parent_id.to_s,
|
41
|
-
annotations: @annotations.map
|
42
|
-
binaryAnnotations: @binary_annotations.map
|
41
|
+
annotations: @annotations.map(&:to_h),
|
42
|
+
binaryAnnotations: @binary_annotations.map(&:to_h),
|
43
43
|
timestamp: @timestamp,
|
44
44
|
duration: @duration,
|
45
45
|
debug: @debug
|
@@ -97,8 +97,6 @@ module Trace
|
|
97
97
|
|
98
98
|
# This class is defined in finagle-thrift. We are adding extra methods here
|
99
99
|
class Endpoint
|
100
|
-
LOCALHOST = '127.0.0.1'.freeze
|
101
|
-
LOCALHOST_I32 = 0x7f000001.freeze
|
102
100
|
UNKNOWN_URL = 'unknown'.freeze
|
103
101
|
|
104
102
|
# we cannot override the initializer to add an extra parameter so use a factory
|
@@ -124,13 +122,7 @@ module Trace
|
|
124
122
|
|
125
123
|
private
|
126
124
|
def self.make_endpoint(hostname, service_port, service_name, ip_format)
|
127
|
-
|
128
|
-
ip_format == :string ? Socket.getaddrinfo(hostname, nil, :INET)[0][3] : host_to_i32(hostname)
|
129
|
-
rescue
|
130
|
-
ip_format == :string ? LOCALHOST : LOCALHOST_I32
|
131
|
-
end
|
132
|
-
|
133
|
-
ep = Endpoint.new(ipv4, service_port, service_name)
|
125
|
+
ep = Endpoint.new(hostname, service_port, service_name)
|
134
126
|
ep.ip_format = ip_format
|
135
127
|
ep
|
136
128
|
end
|
@@ -1,16 +1,18 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'sucker_punch'
|
3
3
|
require 'zipkin-tracer/zipkin_tracer_base'
|
4
|
+
require 'zipkin-tracer/hostname_resolver'
|
4
5
|
|
5
6
|
class AsyncJsonApiClient
|
6
7
|
include SuckerPunch::Job
|
7
8
|
SPANS_PATH = '/api/v1/spans'
|
8
9
|
|
9
10
|
def perform(json_api_host, spans)
|
11
|
+
spans_with_ips = ::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans).map(&:to_h)
|
10
12
|
resp = Faraday.new(json_api_host).post do |req|
|
11
13
|
req.url SPANS_PATH
|
12
14
|
req.headers['Content-Type'] = 'application/json'
|
13
|
-
req.body = JSON.generate(
|
15
|
+
req.body = JSON.generate(spans_with_ips)
|
14
16
|
end
|
15
17
|
rescue => e
|
16
18
|
SuckerPunch.logger.error(e)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'hermann/producer'
|
2
2
|
require 'hermann/discovery/zookeeper'
|
3
3
|
require 'zipkin-tracer/zipkin_tracer_base'
|
4
|
+
require 'zipkin-tracer/hostname_resolver'
|
4
5
|
|
5
6
|
module Trace
|
6
7
|
# This class sends information to Zipkin through Kafka.
|
@@ -16,7 +17,8 @@ module Trace
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def flush!
|
19
|
-
|
20
|
+
resolved_spans = ::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans)
|
21
|
+
resolved_spans.each do |span|
|
20
22
|
buf = ''
|
21
23
|
trans = Thrift::MemoryBufferTransport.new(buf)
|
22
24
|
oprot = Thrift::BinaryProtocol.new(trans)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'zipkin-tracer/zipkin_tracer_base'
|
2
|
+
require 'zipkin-tracer/hostname_resolver'
|
2
3
|
|
3
4
|
module Trace
|
4
5
|
class ZipkinLoggerTracer < ZipkinTracerBase
|
@@ -9,7 +10,8 @@ module Trace
|
|
9
10
|
end
|
10
11
|
|
11
12
|
def flush!
|
12
|
-
|
13
|
+
formatted_spans = ::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans).map(&:to_h)
|
14
|
+
@logger.info "ZIPKIN SPANS: #{formatted_spans}"
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'zipkin-tracer/zipkin_tracer_base'
|
2
2
|
require 'zipkin-tracer/careless_scribe'
|
3
|
+
require 'zipkin-tracer/hostname_resolver'
|
4
|
+
|
3
5
|
|
4
6
|
module Trace
|
5
7
|
class ScribeTracer < ZipkinTracerBase
|
@@ -11,8 +13,9 @@ module Trace
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def flush!
|
16
|
+
resolved_spans = ::ZipkinTracer::HostnameResolver.new.spans_with_ips(spans)
|
14
17
|
@scribe.batch do
|
15
|
-
messages =
|
18
|
+
messages = resolved_spans.map do |span|
|
16
19
|
buf = ''
|
17
20
|
trans = Thrift::MemoryBufferTransport.new(buf)
|
18
21
|
oprot = Thrift::BinaryProtocol.new(trans)
|
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.15.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-02-
|
16
|
+
date: 2016-02-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -63,14 +63,14 @@ dependencies:
|
|
63
63
|
requirements:
|
64
64
|
- - ~>
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: '1.
|
66
|
+
version: '1.6'
|
67
67
|
type: :runtime
|
68
68
|
prerelease: false
|
69
69
|
version_requirements: !ruby/object:Gem::Requirement
|
70
70
|
requirements:
|
71
71
|
- - ~>
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: '1.
|
73
|
+
version: '1.6'
|
74
74
|
- !ruby/object:Gem::Dependency
|
75
75
|
name: rspec
|
76
76
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/zipkin-tracer/careless_scribe.rb
|
187
187
|
- lib/zipkin-tracer/config.rb
|
188
188
|
- lib/zipkin-tracer/faraday/zipkin-tracer.rb
|
189
|
+
- lib/zipkin-tracer/hostname_resolver.rb
|
189
190
|
- lib/zipkin-tracer/rack/zipkin-tracer.rb
|
190
191
|
- lib/zipkin-tracer/trace.rb
|
191
192
|
- lib/zipkin-tracer/trace_client.rb
|