zipkin-tracer 0.39.2 → 0.40.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/zipkin-tracer.rb +1 -0
- data/lib/zipkin-tracer/rack/zipkin_env.rb +21 -10
- data/lib/zipkin-tracer/version.rb +1 -1
- data/lib/zipkin-tracer/zipkin_b3_single_header_format.rb +28 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89503d98e1ff564251c21bcd3f80b3e03f166ed440ddc2515a19b5feea4bf8a4
|
4
|
+
data.tar.gz: ac25d751311eac11ef50f7c2fcae652b1e7dc2c32c036150d9dce898a514a2ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a8edaaf8193c5ad52e3840b354813960b4fbe81e731ab1c220cb3d2e2bf50f6b3e0d258916584a186bbdb4aac8520e538ddc92154c3ce74d8877050256d4230
|
7
|
+
data.tar.gz: 465f582f1ec8438c6ca8d03546229f2fdad1b8975264dc55cf0cbcdd9984095cfad90834a64c6c9ecde55222e6e0495bb69a25d9cb9cb202a36046f3bed300ba
|
data/CHANGELOG.md
CHANGED
data/lib/zipkin-tracer.rb
CHANGED
@@ -10,33 +10,44 @@ module ZipkinTracer
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def trace_id(default_flags = Trace::Flags::EMPTY)
|
13
|
-
trace_id, span_id, parent_span_id, shared = retrieve_or_generate_ids
|
14
|
-
sampled = sampled_header_value(
|
15
|
-
flags = (
|
13
|
+
trace_id, span_id, parent_span_id, sampled, flags, shared = retrieve_or_generate_ids
|
14
|
+
sampled = sampled_header_value(sampled)
|
15
|
+
flags = (flags || default_flags).to_i
|
16
16
|
Trace::TraceId.new(trace_id, parent_span_id, span_id, sampled, flags, shared)
|
17
17
|
end
|
18
18
|
|
19
|
+
def called_with_zipkin_b3_single_header?
|
20
|
+
@called_with_zipkin_b3_single_header ||= @env.key?(B3_SINGLE_HEADER)
|
21
|
+
end
|
22
|
+
|
19
23
|
def called_with_zipkin_headers?
|
20
24
|
@called_with_zipkin_headers ||= B3_REQUIRED_HEADERS.all? { |key| @env.key?(key) }
|
21
25
|
end
|
22
26
|
|
23
27
|
private
|
24
28
|
|
25
|
-
|
26
|
-
|
29
|
+
B3_SINGLE_HEADER = 'HTTP_B3'.freeze
|
30
|
+
B3_REQUIRED_HEADERS = %w[HTTP_X_B3_TRACEID HTTP_X_B3_SPANID].freeze
|
31
|
+
B3_OPT_HEADERS = %w[HTTP_X_B3_PARENTSPANID HTTP_X_B3_SAMPLED HTTP_X_B3_FLAGS].freeze
|
27
32
|
|
28
33
|
def retrieve_or_generate_ids
|
29
|
-
if
|
30
|
-
trace_id, span_id =
|
31
|
-
|
34
|
+
if called_with_zipkin_b3_single_header?
|
35
|
+
trace_id, span_id, parent_span_id, sampled, flags =
|
36
|
+
B3SingleHeaderFormat.parse_from_header(@env[B3_SINGLE_HEADER])
|
32
37
|
shared = true
|
33
|
-
|
38
|
+
elsif called_with_zipkin_headers?
|
39
|
+
trace_id, span_id, parent_span_id, sampled, flags = @env.values_at(*B3_REQUIRED_HEADERS, *B3_OPT_HEADERS)
|
40
|
+
shared = true
|
41
|
+
end
|
42
|
+
|
43
|
+
unless trace_id
|
34
44
|
span_id = TraceGenerator.new.generate_id
|
35
45
|
trace_id = TraceGenerator.new.generate_id_from_span_id(span_id)
|
36
46
|
parent_span_id = nil
|
37
47
|
shared = false
|
38
48
|
end
|
39
|
-
|
49
|
+
|
50
|
+
[trace_id, span_id, parent_span_id, sampled, flags, shared]
|
40
51
|
end
|
41
52
|
|
42
53
|
def new_sampled_header_value(sampled)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ZipkinTracer
|
4
|
+
# This format corresponds to the propagation key "b3" (or "B3").
|
5
|
+
# b3: {x-b3-traceid}-{x-b3-spanid}-{if x-b3-flags 'd' else x-b3-sampled}-{x-b3-parentspanid}
|
6
|
+
# For details, see: https://github.com/openzipkin/b3-propagation
|
7
|
+
class B3SingleHeaderFormat
|
8
|
+
def self.parse_from_header(b3_single_header)
|
9
|
+
if b3_single_header.size == 1
|
10
|
+
flag = b3_single_header
|
11
|
+
else
|
12
|
+
trace_id, span_id, flag, parent_span_id = b3_single_header.split('-')
|
13
|
+
end
|
14
|
+
[trace_id, span_id, parent_span_id, parse_sampled(flag), parse_flags(flag)]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_sampled(flag)
|
18
|
+
case flag
|
19
|
+
when '1', '0'
|
20
|
+
flag
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.parse_flags(flag)
|
25
|
+
flag == 'd' ? Trace::Flags::DEBUG : Trace::Flags::EMPTY
|
26
|
+
end
|
27
|
+
end
|
28
|
+
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.40.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franklin Hu
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2019-
|
17
|
+
date: 2019-10-09 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: faraday
|
@@ -225,6 +225,7 @@ files:
|
|
225
225
|
- lib/zipkin-tracer/trace_wrapper.rb
|
226
226
|
- lib/zipkin-tracer/tracer_factory.rb
|
227
227
|
- lib/zipkin-tracer/version.rb
|
228
|
+
- lib/zipkin-tracer/zipkin_b3_single_header_format.rb
|
228
229
|
- lib/zipkin-tracer/zipkin_http_sender.rb
|
229
230
|
- lib/zipkin-tracer/zipkin_kafka_sender.rb
|
230
231
|
- lib/zipkin-tracer/zipkin_logger_sender.rb
|