zipkin-tracer 0.27.2.1 → 0.28.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 +10 -2
- data/lib/zipkin-tracer/rack/zipkin_env.rb +2 -1
- data/lib/zipkin-tracer/trace.rb +35 -1
- data/lib/zipkin-tracer/trace_generator.rb +19 -1
- data/lib/zipkin-tracer/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fd814c00e7d43bd9fbd4678181407182904b369759f480c4334060f0de76a7b
|
4
|
+
data.tar.gz: 207b8aba87d59166639646babb7c86d174a9880bca955e0e4a3e7d67ed40f49c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd5ff092a5b46f170a6978cdf5e88c2239e35abafb7b7c8d00a29cf9eaa007549dc18a15eb4e3172ec3152e4a2a12d589173e42f7d7fc405384defd8505ea6b2
|
7
|
+
data.tar.gz: f9fece44e302cac6ede9a0023b5ab68683bef98cd300bc978998d403d9a8f528068c4f184fb3e69dcb4fae1c22bf5f47f26b7e6749bf2bba09a3c47df1445300
|
data/lib/zipkin-tracer/config.rb
CHANGED
@@ -9,7 +9,7 @@ module ZipkinTracer
|
|
9
9
|
:zookeeper, :sample_rate, :logger, :log_tracing,
|
10
10
|
:annotate_plugin, :filter_plugin, :whitelist_plugin,
|
11
11
|
:sampled_as_boolean, :record_on_server_receive,
|
12
|
-
:kafka_producer, :kafka_topic
|
12
|
+
:kafka_producer, :kafka_topic, :trace_id_128bit
|
13
13
|
|
14
14
|
def initialize(app, config_hash)
|
15
15
|
config = config_hash || Application.config(app)
|
@@ -46,7 +46,14 @@ module ZipkinTracer
|
|
46
46
|
# Record the given tags on server receive, even if the zipkin headers were present in the incoming request?
|
47
47
|
@record_on_server_receive = parse_tags(config[:record_on_server_receive])
|
48
48
|
|
49
|
+
# When set to true, high 8-bytes will be prepended to trace_id.
|
50
|
+
# The upper 4-bytes are epoch seconds and the lower 4-bytes are random.
|
51
|
+
# This makes it convertible to Amazon X-Ray trace ID format v1.
|
52
|
+
# (See http://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-request-tracing.html)
|
53
|
+
@trace_id_128bit = config[:trace_id_128bit].nil? ? DEFAULTS[:trace_id_128bit] : config[:trace_id_128bit]
|
54
|
+
|
49
55
|
Trace.sample_rate = @sample_rate
|
56
|
+
Trace.trace_id_128bit = @trace_id_128bit
|
50
57
|
end
|
51
58
|
|
52
59
|
def adapter
|
@@ -68,7 +75,8 @@ module ZipkinTracer
|
|
68
75
|
DEFAULTS = {
|
69
76
|
sample_rate: 0.1,
|
70
77
|
service_port: 80,
|
71
|
-
sampled_as_boolean: true
|
78
|
+
sampled_as_boolean: true,
|
79
|
+
trace_id_128bit: false
|
72
80
|
}
|
73
81
|
|
74
82
|
def parse_tags(tag_names)
|
@@ -34,7 +34,8 @@ module ZipkinTracer
|
|
34
34
|
trace_id, span_id = @env.values_at(*B3_REQUIRED_HEADERS)
|
35
35
|
parent_span_id = @env['HTTP_X_B3_PARENTSPANID']
|
36
36
|
else
|
37
|
-
|
37
|
+
span_id = Trace.generate_id
|
38
|
+
trace_id = TraceGenerator.new.generate_id_from_span_id(span_id)
|
38
39
|
parent_span_id = nil
|
39
40
|
end
|
40
41
|
[trace_id, span_id, parent_span_id]
|
data/lib/zipkin-tracer/trace.rb
CHANGED
@@ -3,6 +3,7 @@ require 'zipkin-tracer/zipkin_tracer_base'
|
|
3
3
|
# Module with a mix of functions and overwrites from the finagle implementation:
|
4
4
|
# https://github.com/twitter/finagle/blob/finagle-6.39.0/finagle-thrift/src/main/ruby/lib/finagle-thrift/trace.rb
|
5
5
|
module Trace
|
6
|
+
attr_accessor :trace_id_128bit
|
6
7
|
|
7
8
|
# We need this to access the tracer from the Faraday middleware.
|
8
9
|
def self.tracer
|
@@ -19,7 +20,7 @@ module Trace
|
|
19
20
|
attr_reader :trace_id, :parent_id, :span_id, :sampled, :flags
|
20
21
|
|
21
22
|
def initialize(trace_id, parent_id, span_id, sampled, flags)
|
22
|
-
@trace_id = SpanId.from_value(trace_id)
|
23
|
+
@trace_id = Trace.trace_id_128bit ? TraceId128Bit.from_value(trace_id) : SpanId.from_value(trace_id)
|
23
24
|
@parent_id = parent_id.nil? ? nil : SpanId.from_value(parent_id)
|
24
25
|
@span_id = SpanId.from_value(span_id)
|
25
26
|
@sampled = sampled
|
@@ -44,6 +45,39 @@ module Trace
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
# This class is the 128-bit version of the SpanId class:
|
49
|
+
# https://github.com/twitter/finagle/blob/finagle-6.39.0/finagle-thrift/src/main/ruby/lib/finagle-thrift/trace.rb#L102
|
50
|
+
class TraceId128Bit < SpanId
|
51
|
+
HEX_REGEX_16 = /^[a-f0-9]{16}$/i
|
52
|
+
HEX_REGEX_32 = /^[a-f0-9]{32}$/i
|
53
|
+
MAX_SIGNED_I128 = (2 ** 128 / 2) -1
|
54
|
+
MASK = (2 ** 128) - 1
|
55
|
+
|
56
|
+
def self.from_value(v)
|
57
|
+
if v.is_a?(String) && v =~ HEX_REGEX_16
|
58
|
+
SpanId.new(v.hex)
|
59
|
+
elsif v.is_a?(String) && v =~ HEX_REGEX_32
|
60
|
+
new(v.hex)
|
61
|
+
elsif v.is_a?(Numeric)
|
62
|
+
new(v)
|
63
|
+
elsif v.is_a?(SpanId)
|
64
|
+
v
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def initialize(value)
|
69
|
+
@value = value
|
70
|
+
@i128 = if @value > MAX_SIGNED_I128
|
71
|
+
-1 * ((@value ^ MASK) + 1)
|
72
|
+
else
|
73
|
+
@value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def to_s; '%032x' % @value; end
|
78
|
+
def to_i; @i128; end
|
79
|
+
end
|
80
|
+
|
47
81
|
# A span may contain many annotations
|
48
82
|
# This class is defined in finagle-thrift. We are adding extra methods here
|
49
83
|
class Span
|
@@ -12,20 +12,38 @@ module ZipkinTracer
|
|
12
12
|
|
13
13
|
def generate_trace_id
|
14
14
|
span_id = generate_id
|
15
|
-
Trace::TraceId.new(span_id, nil, span_id, should_sample?.to_s, Trace::Flags::EMPTY)
|
15
|
+
Trace::TraceId.new(generate_id_from_span_id(span_id), nil, span_id, should_sample?.to_s, Trace::Flags::EMPTY)
|
16
16
|
end
|
17
17
|
|
18
18
|
def should_sample?
|
19
19
|
rand < (Trace.sample_rate || DEFAULT_SAMPLE_RATE)
|
20
20
|
end
|
21
21
|
|
22
|
+
def generate_id_from_span_id(span_id)
|
23
|
+
Trace.trace_id_128bit ? generate_id_128bit(span_id) : span_id
|
24
|
+
end
|
25
|
+
|
22
26
|
private
|
23
27
|
|
24
28
|
def generate_id
|
25
29
|
rand(TRACE_ID_UPPER_BOUND)
|
26
30
|
end
|
27
31
|
|
32
|
+
def generate_id_128bit(span_id)
|
33
|
+
trace_id_low_64bit = '%016x' % span_id
|
34
|
+
"#{trace_id_epoch_seconds}#{trace_id_high_32bit}#{trace_id_low_64bit}".hex
|
35
|
+
end
|
36
|
+
|
37
|
+
def trace_id_epoch_seconds
|
38
|
+
'%08x' % Time.now.to_i
|
39
|
+
end
|
40
|
+
|
41
|
+
def trace_id_high_32bit
|
42
|
+
'%08x' % rand(TRACE_ID_HIGH_32BIT_UPPER_BOUND)
|
43
|
+
end
|
44
|
+
|
28
45
|
TRACE_ID_UPPER_BOUND = 2**64
|
46
|
+
TRACE_ID_HIGH_32BIT_UPPER_BOUND = 2**32
|
29
47
|
DEFAULT_SAMPLE_RATE = 0.001
|
30
48
|
end
|
31
49
|
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.28.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: 2018-
|
16
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: faraday
|
@@ -207,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
version: 1.3.5
|
208
208
|
requirements: []
|
209
209
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.7.
|
210
|
+
rubygems_version: 2.7.6
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
213
|
summary: Ruby tracing via Zipkin
|