zipkin-tracer 0.18.6 → 0.19.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 +4 -4
- data/lib/zipkin-tracer/config.rb +22 -2
- data/lib/zipkin-tracer/rack/zipkin-tracer.rb +18 -5
- data/lib/zipkin-tracer/trace.rb +31 -0
- data/lib/zipkin-tracer/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fada20597d32e18a27712d3031e895f28212c637
|
4
|
+
data.tar.gz: b57584551882c44615be24783c3ea30fb9e8604b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 906d2105340d18be042320a3a7d1168e1efb417dd1dc1099fb62a16954c7791aef587e4823df19a688bafc3e4405056e996761a49b40f4bc11a284799bf370b7
|
7
|
+
data.tar.gz: 321783d91739fb623f511d0bb0cff16341f0095282e76ffac91389c5d5b00219fb801775a9908ea0da760dd354fab053a12a687be83e3cb58453eac137b3660d
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -6,20 +6,39 @@ module ZipkinTracer
|
|
6
6
|
class Config
|
7
7
|
attr_reader :service_name, :service_port, :json_api_host,
|
8
8
|
:zookeeper, :sample_rate, :logger, :log_tracing,
|
9
|
-
:annotate_plugin, :filter_plugin, :whitelist_plugin
|
9
|
+
:annotate_plugin, :filter_plugin, :whitelist_plugin,
|
10
|
+
:sampled_as_boolean
|
10
11
|
|
11
12
|
def initialize(app, config_hash)
|
12
13
|
config = config_hash || Application.config(app)
|
14
|
+
# The name of the current service
|
13
15
|
@service_name = config[:service_name]
|
16
|
+
# The port where the current service is running
|
14
17
|
@service_port = config[:service_port] || DEFAULTS[:service_port]
|
18
|
+
# The address of the Zipkin server which we will send traces to
|
15
19
|
@json_api_host = config[:json_api_host]
|
20
|
+
# Zookeeper information
|
16
21
|
@zookeeper = config[:zookeeper]
|
22
|
+
# Percentage of traces which by default this service traces (as float, 1.0 means 100%)
|
17
23
|
@sample_rate = config[:sample_rate] || DEFAULTS[:sample_rate]
|
24
|
+
# A block of code which can be called to do extra annotations of traces
|
18
25
|
@annotate_plugin = config[:annotate_plugin] # call for trace annotation
|
19
26
|
@filter_plugin = config[:filter_plugin] # skip tracing if returns false
|
20
27
|
@whitelist_plugin = config[:whitelist_plugin] # force sampling if returns true
|
28
|
+
# A block of code which can be called to skip traces. Skip tracing if returns false
|
29
|
+
@filter_plugin = config[:filter_plugin]
|
30
|
+
# A block of code which can be called to force sampling. Forces sampling if returns true
|
31
|
+
@whitelist_plugin = config[:whitelist_plugin]
|
21
32
|
@logger = Application.logger
|
22
33
|
@log_tracing = config[:log_tracing] # Was the logger in fact setup by the client?
|
34
|
+
# Was the logger in fact setup by the client?
|
35
|
+
@log_tracing = config[:log_tracing]
|
36
|
+
# When set to false, it uses 1/0 in the 'X-B3-Sampled' header, else uses true/false
|
37
|
+
@sampled_as_boolean = config[:sampled_as_boolean] || DEFAULTS[:sampled_as_boolean]
|
38
|
+
# The current default is true for compatibility but services are encouraged to move on.
|
39
|
+
if @sampled_as_boolean
|
40
|
+
@logger && @logger.warn("Using a boolean in the Sampled header is deprecated. Consider setting sampled_as_boolean to false")
|
41
|
+
end
|
23
42
|
end
|
24
43
|
|
25
44
|
def adapter
|
@@ -38,7 +57,8 @@ module ZipkinTracer
|
|
38
57
|
|
39
58
|
DEFAULTS = {
|
40
59
|
sample_rate: 0.1,
|
41
|
-
service_port: 80
|
60
|
+
service_port: 80,
|
61
|
+
sampled_as_boolean: true
|
42
62
|
}
|
43
63
|
|
44
64
|
def present?(str)
|
@@ -83,9 +83,9 @@ module ZipkinTracer
|
|
83
83
|
@env.values_at(*B3_REQUIRED_HEADERS)
|
84
84
|
else
|
85
85
|
new_id = Trace.generate_id
|
86
|
-
[new_id, nil, new_id]
|
86
|
+
[new_id, nil, new_id, nil]
|
87
87
|
end
|
88
|
-
trace_parameters[3] =
|
88
|
+
trace_parameters[3] = sampled_header_value(trace_parameters[3])
|
89
89
|
trace_parameters += @env.values_at(*B3_OPT_HEADERS) # always check flags
|
90
90
|
trace_parameters[4] = (trace_parameters[4] || default_flags).to_i
|
91
91
|
|
@@ -102,15 +102,28 @@ module ZipkinTracer
|
|
102
102
|
|
103
103
|
private
|
104
104
|
|
105
|
+
def new_sampled_header_value(sampled)
|
106
|
+
case [@config.sampled_as_boolean, sampled]
|
107
|
+
when [true, true]
|
108
|
+
'true'
|
109
|
+
when [true, false]
|
110
|
+
'false'
|
111
|
+
when [false, true]
|
112
|
+
'1'
|
113
|
+
when [false, false]
|
114
|
+
'0'
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
105
118
|
def current_trace_sampled?
|
106
119
|
rand < @config.sample_rate
|
107
120
|
end
|
108
121
|
|
109
|
-
def
|
122
|
+
def sampled_header_value(parent_trace_sampled)
|
110
123
|
if parent_trace_sampled # A service upstream decided this goes in all the way
|
111
|
-
parent_trace_sampled
|
124
|
+
parent_trace_sampled
|
112
125
|
else
|
113
|
-
force_sample? || current_trace_sampled? && !filtered?
|
126
|
+
new_sampled_header_value(force_sample? || current_trace_sampled? && !filtered?)
|
114
127
|
end
|
115
128
|
end
|
116
129
|
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -15,6 +15,37 @@ module Trace
|
|
15
15
|
self.pop
|
16
16
|
end
|
17
17
|
|
18
|
+
# A TraceId contains all the information of a given trace id
|
19
|
+
# This class is defined in finagle-thrift. We are overwriting it here
|
20
|
+
class TraceId
|
21
|
+
attr_reader :trace_id, :parent_id, :span_id, :sampled, :flags
|
22
|
+
|
23
|
+
def initialize(trace_id, parent_id, span_id, sampled, flags)
|
24
|
+
@trace_id = SpanId.from_value(trace_id)
|
25
|
+
@parent_id = parent_id.nil? ? nil : SpanId.from_value(parent_id)
|
26
|
+
@span_id = SpanId.from_value(span_id)
|
27
|
+
@sampled = sampled
|
28
|
+
@flags = flags
|
29
|
+
end
|
30
|
+
|
31
|
+
def next_id
|
32
|
+
TraceId.new(@trace_id, @span_id, Trace.generate_id, @sampled, @flags)
|
33
|
+
end
|
34
|
+
|
35
|
+
# the debug flag is used to ensure the trace passes ALL samplers
|
36
|
+
def debug?
|
37
|
+
@flags & Flags::DEBUG == Flags::DEBUG
|
38
|
+
end
|
39
|
+
|
40
|
+
def sampled?
|
41
|
+
debug? || ['1', 'true'].include?(@sampled)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_s
|
45
|
+
"TraceId(trace_id = #{@trace_id.to_s}, parent_id = #{@parent_id.to_s}, span_id = #{@span_id.to_s}, sampled = #{@sampled.to_s}, flags = #{@flags.to_s})"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
18
49
|
# A span may contain many annotations
|
19
50
|
# This class is defined in finagle-thrift. We are adding extra methods here
|
20
51
|
class Span
|
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.19.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-11-
|
16
|
+
date: 2016-11-26 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -35,14 +35,14 @@ dependencies:
|
|
35
35
|
requirements:
|
36
36
|
- - "~>"
|
37
37
|
- !ruby/object:Gem::Version
|
38
|
-
version: 1.4.
|
38
|
+
version: 1.4.2
|
39
39
|
type: :runtime
|
40
40
|
prerelease: false
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
43
|
- - "~>"
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version: 1.4.
|
45
|
+
version: 1.4.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: rack
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|