zipkin-tracer 0.10.3 → 0.11.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 +8 -8
- data/lib/zipkin-tracer/faraday/zipkin-tracer.rb +10 -9
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +10 -13
- data/lib/zipkin-tracer/trace.rb +14 -0
- data/lib/zipkin-tracer/tracer_factory.rb +3 -3
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/zipkin_null_tracer.rb +11 -0
- data/lib/zipkin-tracer/zipkin_scribe_tracer.rb +27 -0
- data/lib/zipkin-tracer/zipkin_tracer_base.rb +13 -25
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmU0MDJhYzQxZGM5ODVkZmI0NzliYzI3MGQ0MmRhYjUyNmRhNjE2MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWQ3ZDNhMmY4YjhkMmUxZDgwOTY5NzIyZGU0NzJkYjNmNGFkZGM0Zg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmRlMTEzYmEzYzM5YmQ4MzllNTViZDdjOWY0ZmU1YzMzYjYxZjZlZWM5MGFl
|
10
|
+
NWU3OGVmMDA1MGJiZTA0Y2I5M2M4ZTRiOGZkMTJiYWI2ZmU1NTY5NTM4MWU2
|
11
|
+
NWY3MWFjZDEzNzY0N2UwMmJkZDBiNWM4NTcxNjU5YzhiYzA0YmY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NmNjMzA2OWQzYmE5ZGVkNDNjOWM5ODkyZjYxZjZiN2FmMWM5MjljMTdjODdh
|
14
|
+
ZGQ4YjVlOWFmOWMzODgyMWEyNWZlNzdjODk4YjA5ODk0YTU0ZjM1NjBjNTRh
|
15
|
+
MzVjZmFmZmY2YmIzMDRhYjU1MWIxOGRlMTRhY2M1NzBjMTBlMzI=
|
@@ -49,16 +49,17 @@ module ZipkinTracer
|
|
49
49
|
url = env[:url].respond_to?(:host) ? env[:url] : URI.parse(env[:url].to_s)
|
50
50
|
local_endpoint = Trace.default_endpoint # The rack middleware set this up for us.
|
51
51
|
remote_endpoint = callee_endpoint(url, local_endpoint.ip_format) # The endpoint we are calling.
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
@tracer.with_new_span(trace_id, env[:method].to_s.downcase) do |span|
|
53
|
+
# annotate with method (GET/POST/etc.) and uri path
|
54
|
+
span.record(Trace::BinaryAnnotation.new(URI_KEY, url.path, STRING_TYPE, local_endpoint))
|
55
|
+
span.record(Trace::BinaryAnnotation.new(SERVER_ADDRESS, SERVER_ADDRESS_SPECIAL_VALUE, BOOLEAN_TYPE, remote_endpoint))
|
56
|
+
span.record(Trace::Annotation.new(Trace::Annotation::CLIENT_SEND, local_endpoint))
|
57
|
+
response = @app.call(env).on_complete do |renv|
|
58
|
+
# record HTTP status code on response
|
59
|
+
span.record(Trace::BinaryAnnotation.new(STATUS_KEY, renv[:status].to_s, STRING_TYPE, local_endpoint))
|
60
|
+
end
|
61
|
+
span.record(Trace::Annotation.new(Trace::Annotation::CLIENT_RECV, local_endpoint))
|
60
62
|
end
|
61
|
-
@tracer.record(trace_id, Trace::Annotation.new(Trace::Annotation::CLIENT_RECV, local_endpoint))
|
62
63
|
response
|
63
64
|
end
|
64
65
|
|
@@ -38,7 +38,9 @@ module ZipkinTracer
|
|
38
38
|
if !trace_id.sampled? || !routable_request?(env)
|
39
39
|
@app.call(env)
|
40
40
|
else
|
41
|
-
|
41
|
+
@tracer.with_new_span(trace_id, zipkin_env.env['REQUEST_METHOD'].to_s.downcase) do |span|
|
42
|
+
trace!(span, zipkin_env) { @app.call(env) }
|
43
|
+
end
|
42
44
|
end
|
43
45
|
end
|
44
46
|
end
|
@@ -52,10 +54,6 @@ module ZipkinTracer
|
|
52
54
|
Trace.pop
|
53
55
|
end
|
54
56
|
|
55
|
-
def record(annotation)
|
56
|
-
@tracer.record(@trace_id, annotation)
|
57
|
-
end
|
58
|
-
|
59
57
|
# If the request is not valid for this service, we do not what to trace it.
|
60
58
|
def routable_request?(env)
|
61
59
|
return true unless defined?(Rails) # If not running on a Rails app, we can't verify if it is invalid
|
@@ -69,24 +67,23 @@ module ZipkinTracer
|
|
69
67
|
@config.annotate_plugin.call(env, status, response_headers, response_body) if @config.annotate_plugin
|
70
68
|
end
|
71
69
|
|
72
|
-
def trace!(
|
70
|
+
def trace!(span, zipkin_env, &block)
|
73
71
|
synchronize do
|
74
72
|
#if called by a service, the caller already added the information
|
75
|
-
trace_request_information(
|
76
|
-
|
77
|
-
|
73
|
+
trace_request_information(span, zipkin_env.env) unless zipkin_env.called_with_zipkin_headers?
|
74
|
+
span.record(Trace::Annotation.new(Trace::Annotation::SERVER_RECV, Trace.default_endpoint))
|
75
|
+
span.record(Trace::Annotation.new('whitelisted', Trace.default_endpoint)) if zipkin_env.force_sample?
|
78
76
|
end
|
79
77
|
status, headers, body = yield
|
80
78
|
ensure
|
81
79
|
synchronize do
|
82
80
|
annotate_plugin(zipkin_env.env, status, headers, body)
|
83
|
-
|
81
|
+
span.record(Trace::Annotation.new(Trace::Annotation::SERVER_SEND, Trace.default_endpoint))
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
87
|
-
def trace_request_information(
|
88
|
-
|
89
|
-
@tracer.record(trace_id, Trace::BinaryAnnotation.new('http.uri', env['PATH_INFO'], 'STRING', Trace.default_endpoint))
|
85
|
+
def trace_request_information(span, env)
|
86
|
+
span.record(Trace::BinaryAnnotation.new('http.uri', env['PATH_INFO'], 'STRING', Trace.default_endpoint))
|
90
87
|
end
|
91
88
|
|
92
89
|
def synchronize(&block)
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -9,6 +9,20 @@ module Trace
|
|
9
9
|
end
|
10
10
|
|
11
11
|
class Span
|
12
|
+
attr_reader :size
|
13
|
+
|
14
|
+
# We record information into spans, then we send these spans to zipkin
|
15
|
+
def record(annotation)
|
16
|
+
@size ||= 0
|
17
|
+
case annotation
|
18
|
+
when BinaryAnnotation
|
19
|
+
binary_annotations << annotation
|
20
|
+
when Annotation
|
21
|
+
annotations << annotation
|
22
|
+
end
|
23
|
+
@size = @size + 1
|
24
|
+
end
|
25
|
+
|
12
26
|
def to_h
|
13
27
|
{
|
14
28
|
name: @name,
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
module ZipkinTracer
|
3
2
|
class TracerFactory
|
4
3
|
def tracer(config)
|
@@ -10,12 +9,13 @@ module ZipkinTracer
|
|
10
9
|
options = { json_api_host: config.json_api_host, traces_buffer: config.traces_buffer, logger: config.logger }
|
11
10
|
Trace::ZipkinJsonTracer.new(options)
|
12
11
|
when :scribe
|
13
|
-
require 'zipkin-tracer/
|
14
|
-
Trace::
|
12
|
+
require 'zipkin-tracer/zipkin_scribe_tracer'
|
13
|
+
Trace::ScribeTracer.new(scribe_server: config.scribe_server, traces_buffer: config.scribe_max_buffer)
|
15
14
|
when :kafka
|
16
15
|
require 'zipkin-tracer/zipkin_kafka_tracer'
|
17
16
|
Trace::ZipkinKafkaTracer.new(zookeepers: config.zookeeper)
|
18
17
|
else
|
18
|
+
require 'zipkin-tracer/zipkin_null_tracer'
|
19
19
|
Trace::NullTracer.new
|
20
20
|
end
|
21
21
|
Trace.tracer = tracer
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Trace
|
2
|
+
# Monkey patching Nulltracer from thrift.
|
3
|
+
# All our tracers have a start_span method, adding it to
|
4
|
+
# the NullTracer also.
|
5
|
+
class NullTracer
|
6
|
+
def with_new_span(trace_id, name)
|
7
|
+
span = Span.new(name, trace_id)
|
8
|
+
yield span
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'zipkin-tracer/zipkin_tracer_base'
|
2
|
+
require 'zipkin-tracer/careless_scribe'
|
3
|
+
|
4
|
+
module Trace
|
5
|
+
class ScribeTracer < ZipkinTracerBase
|
6
|
+
TRACER_CATEGORY = "zipkin".freeze
|
7
|
+
|
8
|
+
def initialize(options)
|
9
|
+
@scribe = CarelessScribe.new(options[:scribe_server])
|
10
|
+
super(options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def flush!
|
14
|
+
@scribe.batch do
|
15
|
+
messages = spans.values.map do |span|
|
16
|
+
buf = ''
|
17
|
+
trans = Thrift::MemoryBufferTransport.new(buf)
|
18
|
+
oprot = Thrift::BinaryProtocol.new(trans)
|
19
|
+
span.to_thrift.write(oprot)
|
20
|
+
Base64.encode64(buf).gsub("\n", "")
|
21
|
+
end
|
22
|
+
@scribe.log(messages, TRACER_CATEGORY)
|
23
|
+
end
|
24
|
+
reset
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -8,7 +8,6 @@ module Trace
|
|
8
8
|
# Traces dealing with zipkin should inherit from this class and implement the
|
9
9
|
# flush! method which actually sends the information
|
10
10
|
class ZipkinTracerBase < Tracer
|
11
|
-
TRACER_CATEGORY = "zipkin".freeze
|
12
11
|
|
13
12
|
def initialize(options={})
|
14
13
|
@options = options
|
@@ -16,27 +15,25 @@ module Trace
|
|
16
15
|
reset
|
17
16
|
end
|
18
17
|
|
19
|
-
def
|
20
|
-
span =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
when Annotation
|
26
|
-
span.annotations << annotation
|
27
|
-
end
|
28
|
-
count = current_count
|
29
|
-
set_current_count(count + 1)
|
18
|
+
def with_new_span(trace_id, name)
|
19
|
+
span = start_span(trace_id, name)
|
20
|
+
result = yield span
|
21
|
+
may_flush(span)
|
22
|
+
result
|
23
|
+
end
|
30
24
|
|
31
|
-
|
25
|
+
def may_flush(span)
|
26
|
+
size = spans.values.map(&:size).inject(:+) || 0
|
27
|
+
if size >= @traces_buffer || span.annotations.any?{ |ann| ann == Annotation::SERVER_SEND }
|
32
28
|
flush!
|
33
29
|
reset
|
34
30
|
end
|
35
31
|
end
|
36
32
|
|
37
|
-
def
|
38
|
-
span = get_span_for_id(
|
39
|
-
span.name = name
|
33
|
+
def start_span(trace_id, name)
|
34
|
+
span = get_span_for_id(trace_id)
|
35
|
+
span.name = name
|
36
|
+
span
|
40
37
|
end
|
41
38
|
|
42
39
|
def flush!
|
@@ -49,14 +46,6 @@ module Trace
|
|
49
46
|
Thread.current[:zipkin_spans] ||= {}
|
50
47
|
end
|
51
48
|
|
52
|
-
def current_count
|
53
|
-
Thread.current[:zipkin_spans_count] ||= 0
|
54
|
-
end
|
55
|
-
|
56
|
-
def set_current_count(count)
|
57
|
-
Thread.current[:zipkin_spans_count] = count
|
58
|
-
end
|
59
|
-
|
60
49
|
def get_span_for_id(id)
|
61
50
|
key = id.span_id.to_s
|
62
51
|
spans[key] ||= Span.new("", id)
|
@@ -64,7 +53,6 @@ module Trace
|
|
64
53
|
|
65
54
|
def reset
|
66
55
|
Thread.current[:zipkin_spans] = {}
|
67
|
-
set_current_count(0)
|
68
56
|
end
|
69
57
|
end
|
70
58
|
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.11.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-01-
|
16
|
+
date: 2016-01-28 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -191,6 +191,8 @@ files:
|
|
191
191
|
- lib/zipkin-tracer/version.rb
|
192
192
|
- lib/zipkin-tracer/zipkin_json_tracer.rb
|
193
193
|
- lib/zipkin-tracer/zipkin_kafka_tracer.rb
|
194
|
+
- lib/zipkin-tracer/zipkin_null_tracer.rb
|
195
|
+
- lib/zipkin-tracer/zipkin_scribe_tracer.rb
|
194
196
|
- lib/zipkin-tracer/zipkin_tracer_base.rb
|
195
197
|
homepage: https://github.com/openzipkin/zipkin-tracer
|
196
198
|
licenses: []
|