zipkin-tracer 0.12.1 → 0.13.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/config.rb +2 -6
- data/lib/zipkin-tracer/trace.rb +23 -6
- data/lib/zipkin-tracer/trace_client.rb +10 -7
- data/lib/zipkin-tracer/tracer_factory.rb +2 -2
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/zipkin_kafka_tracer.rb +0 -1
- data/lib/zipkin-tracer/zipkin_tracer_base.rb +12 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDAzYzIxYWEzM2Y5NTM1OWJiMWQ5ODkwODVjY2U3YmFjMjkxNjY0Nw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTJlNzYxMzZiZGJkOGU5Y2FhM2Y4OWMzNjIxNzU4NjBjYWVhMjFkNQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTg1MGVmMTJjM2NlMWE0YTlmZmNjYjEyOWJkOWU0MWYyMjdhNjU3MWEwOTcx
|
10
|
+
YzU5N2ZlNzQyOTE4Yjg1MjAzOTJmN2Q2NWY1YTA4OTZmOTZmNzZlNjA5MzRk
|
11
|
+
NDgyMjFjNDJhNWFiMDc4ZmM2OWIxNTVhNGRiZDA1NDE5NWJlYTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGJjZDQwNmQwOTgwZDJlZDUzMjFmMTdjNDI1ZGIzNWRlYzA4YzE3NTUzZTg5
|
14
|
+
ZDE0Y2RmNGFmMjMwYzZkZjBmMzI4M2NlZmIwNGNlM2VmOTNlYWY3MTdkMGZh
|
15
|
+
NTIwM2EwMjQwYmU4OTQ1YmZkYjBmYWI5YTkyOTFjNTEwMjBhYmU=
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -4,8 +4,8 @@ require 'zipkin-tracer/application'
|
|
4
4
|
module ZipkinTracer
|
5
5
|
# Configuration of this gem. It reads the configuration and provides default values
|
6
6
|
class Config
|
7
|
-
attr_reader :service_name, :service_port, :json_api_host,
|
8
|
-
:scribe_server, :zookeeper, :sample_rate, :
|
7
|
+
attr_reader :service_name, :service_port, :json_api_host,
|
8
|
+
:scribe_server, :zookeeper, :sample_rate, :annotate_plugin,
|
9
9
|
:filter_plugin, :whitelist_plugin, :logger
|
10
10
|
|
11
11
|
def initialize(app, config_hash)
|
@@ -13,11 +13,9 @@ module ZipkinTracer
|
|
13
13
|
@service_name = config[:service_name]
|
14
14
|
@service_port = config[:service_port] || DEFAULTS[:service_port]
|
15
15
|
@json_api_host = config[:json_api_host]
|
16
|
-
@traces_buffer = config[:traces_buffer] || DEFAULTS[:traces_buffer]
|
17
16
|
@scribe_server = config[:scribe_server]
|
18
17
|
@zookeeper = config[:zookeeper]
|
19
18
|
@sample_rate = config[:sample_rate] || DEFAULTS[:sample_rate]
|
20
|
-
@scribe_max_buffer = config[:scribe_max_buffer] || DEFAULTS[:scribe_max_buffer]
|
21
19
|
@annotate_plugin = config[:annotate_plugin] # call for trace annotation
|
22
20
|
@filter_plugin = config[:filter_plugin] # skip tracing if returns false
|
23
21
|
@whitelist_plugin = config[:whitelist_plugin] # force sampling if returns true
|
@@ -39,8 +37,6 @@ module ZipkinTracer
|
|
39
37
|
private
|
40
38
|
|
41
39
|
DEFAULTS = {
|
42
|
-
traces_buffer: 100,
|
43
|
-
scribe_max_buffer: 10,
|
44
40
|
sample_rate: 0.1,
|
45
41
|
service_port: 80
|
46
42
|
}
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -18,19 +18,28 @@ module Trace
|
|
18
18
|
# A span may contain many annotations
|
19
19
|
# This class is defined in finagle-thrift. We are adding extra methods here
|
20
20
|
class Span
|
21
|
-
|
22
|
-
|
21
|
+
def initialize(name, span_id)
|
22
|
+
@name = name
|
23
|
+
@span_id = span_id
|
24
|
+
@annotations = []
|
25
|
+
@binary_annotations = []
|
26
|
+
@debug = span_id.debug?
|
27
|
+
@timestamp = to_microseconds(Time.now)
|
28
|
+
@duration = UNKNOWN_DURATION
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
@duration = to_microseconds(Time.now) - @timestamp
|
33
|
+
end
|
23
34
|
|
24
35
|
# We record information into spans, then we send these spans to zipkin
|
25
36
|
def record(annotation)
|
26
|
-
@size ||= 0
|
27
37
|
case annotation
|
28
38
|
when BinaryAnnotation
|
29
39
|
binary_annotations << annotation
|
30
40
|
when Annotation
|
31
41
|
annotations << annotation
|
32
42
|
end
|
33
|
-
@size = @size + 1
|
34
43
|
end
|
35
44
|
|
36
45
|
def to_h
|
@@ -41,11 +50,19 @@ module Trace
|
|
41
50
|
parentId: @span_id.parent_id.nil? ? nil : @span_id.parent_id.to_s,
|
42
51
|
annotations: @annotations.map!(&:to_h),
|
43
52
|
binaryAnnotations: @binary_annotations.map!(&:to_h),
|
44
|
-
timestamp: timestamp,
|
45
|
-
duration: duration,
|
53
|
+
timestamp: @timestamp,
|
54
|
+
duration: @duration,
|
46
55
|
debug: @debug
|
47
56
|
}
|
48
57
|
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
UNKNOWN_DURATION = 0 # mark duration was not set
|
62
|
+
|
63
|
+
def to_microseconds(time)
|
64
|
+
(time.to_f * 1_000_000).to_i
|
65
|
+
end
|
49
66
|
end
|
50
67
|
|
51
68
|
# This class is defined in finagle-thrift. We are adding extra methods here
|
@@ -4,20 +4,23 @@ module ZipkinTracer
|
|
4
4
|
STRING_TYPE = 'STRING'.freeze
|
5
5
|
|
6
6
|
def self.local_component_span(local_component_value, &block)
|
7
|
-
|
8
|
-
|
9
|
-
client.record_local_component local_component_value
|
10
|
-
end
|
7
|
+
client = self.new
|
8
|
+
client.trace(local_component_value, &block)
|
11
9
|
end
|
12
10
|
|
13
|
-
def
|
11
|
+
def trace(local_component_value, &block)
|
12
|
+
raise ArgumentError, "no block given" unless block
|
13
|
+
|
14
14
|
@trace_id = Trace.id.next_id
|
15
|
+
result = nil
|
15
16
|
Trace.with_trace_id(@trace_id) do
|
16
|
-
Trace.tracer.with_new_span(@trace_id,
|
17
|
+
Trace.tracer.with_new_span(@trace_id, LOCAL_COMPONENT) do |span|
|
17
18
|
@span = span
|
18
|
-
block.call(self)
|
19
|
+
result = block.call(self)
|
20
|
+
record_local_component local_component_value
|
19
21
|
end
|
20
22
|
end
|
23
|
+
result
|
21
24
|
end
|
22
25
|
|
23
26
|
def record(key)
|
@@ -6,11 +6,11 @@ module ZipkinTracer
|
|
6
6
|
tracer = case adapter
|
7
7
|
when :json
|
8
8
|
require 'zipkin-tracer/zipkin_json_tracer'
|
9
|
-
options = { json_api_host: config.json_api_host,
|
9
|
+
options = { json_api_host: config.json_api_host, logger: config.logger }
|
10
10
|
Trace::ZipkinJsonTracer.new(options)
|
11
11
|
when :scribe
|
12
12
|
require 'zipkin-tracer/zipkin_scribe_tracer'
|
13
|
-
Trace::ScribeTracer.new(scribe_server: config.scribe_server
|
13
|
+
Trace::ScribeTracer.new(scribe_server: config.scribe_server)
|
14
14
|
when :kafka
|
15
15
|
require 'zipkin-tracer/zipkin_kafka_tracer'
|
16
16
|
Trace::ZipkinKafkaTracer.new(zookeepers: config.zookeeper)
|
@@ -12,7 +12,6 @@ module Trace
|
|
12
12
|
@topic = options[:topic] || DEFAULT_KAFKA_TOPIC
|
13
13
|
broker_ids = Hermann::Discovery::Zookeeper.new(options[:zookeepers]).get_brokers
|
14
14
|
@producer = Hermann::Producer.new(nil, broker_ids)
|
15
|
-
options[:traces_buffer] ||= 1 # Default in Kafka is sending as soon as possible. No buffer.
|
16
15
|
super(options)
|
17
16
|
end
|
18
17
|
|
@@ -11,31 +11,27 @@ module Trace
|
|
11
11
|
|
12
12
|
def initialize(options={})
|
13
13
|
@options = options
|
14
|
-
@traces_buffer = options[:traces_buffer] || raise(ArgumentError, 'A proper buffer must be setup for the Zipkin tracer')
|
15
14
|
reset
|
16
15
|
end
|
17
16
|
|
18
17
|
def with_new_span(trace_id, name)
|
19
18
|
span = start_span(trace_id, name)
|
20
|
-
start_time = Time.now
|
21
|
-
span.timestamp = to_microseconds(start_time)
|
22
19
|
result = yield span
|
23
|
-
span
|
24
|
-
may_flush(span)
|
20
|
+
end_span(span)
|
25
21
|
result
|
26
22
|
end
|
27
23
|
|
28
|
-
def
|
29
|
-
|
30
|
-
if
|
24
|
+
def end_span(span)
|
25
|
+
span.close
|
26
|
+
if span.annotations.any?{ |ann| ann.value == Annotation::SERVER_SEND }
|
31
27
|
flush!
|
32
28
|
reset
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
36
32
|
def start_span(trace_id, name)
|
37
|
-
span =
|
38
|
-
span
|
33
|
+
span = Span.new(name, trace_id)
|
34
|
+
store_span(trace_id, span)
|
39
35
|
span
|
40
36
|
end
|
41
37
|
|
@@ -45,21 +41,19 @@ module Trace
|
|
45
41
|
|
46
42
|
private
|
47
43
|
|
44
|
+
THREAD_KEY = :zipkin_spans
|
45
|
+
|
48
46
|
def spans
|
49
|
-
Thread.current[
|
47
|
+
Thread.current[THREAD_KEY] ||= {}
|
50
48
|
end
|
51
49
|
|
52
|
-
def
|
53
|
-
|
54
|
-
spans[key] ||= Span.new("", id)
|
50
|
+
def store_span(id, span)
|
51
|
+
spans[id.span_id.to_s] = span
|
55
52
|
end
|
56
53
|
|
57
54
|
def reset
|
58
|
-
Thread.current[
|
55
|
+
Thread.current[THREAD_KEY] = {}
|
59
56
|
end
|
60
57
|
|
61
|
-
def to_microseconds(time)
|
62
|
-
(time.to_f * 1_000_000).to_i
|
63
|
-
end
|
64
58
|
end
|
65
59
|
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.13.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-04 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|