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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b824d605a7ca0b7a7022d356e70361ad627a633883d252119bc6b66c10196577
4
- data.tar.gz: d9446b59c3dabef034d47b81c2b98bee94bb03dc0a8cb3fa5c73888b6d7ce0a6
3
+ metadata.gz: 89503d98e1ff564251c21bcd3f80b3e03f166ed440ddc2515a19b5feea4bf8a4
4
+ data.tar.gz: ac25d751311eac11ef50f7c2fcae652b1e7dc2c32c036150d9dce898a514a2ba
5
5
  SHA512:
6
- metadata.gz: fe9a5451b3534373e95a624fa46cdb431f4e8e1de69330115d806dec45e0bcf5c7f86f6c6309b4bc87bb9549bee1cf49973be95ebc945e417e49c94d3c1bc23f
7
- data.tar.gz: 5cea09da7bbcb379b5e96903639b52a70dd046cc8e62df771667c5d7e062256678fe747bc5ecc107a9ada69832f17e84b5301a68a2b5f662d3341102c74165e9
6
+ metadata.gz: 5a8edaaf8193c5ad52e3840b354813960b4fbe81e731ab1c220cb3d2e2bf50f6b3e0d258916584a186bbdb4aac8520e538ddc92154c3ce74d8877050256d4230
7
+ data.tar.gz: 465f582f1ec8438c6ca8d03546229f2fdad1b8975264dc55cf0cbcdd9984095cfad90834a64c6c9ecde55222e6e0495bb69a25d9cb9cb202a36046f3bed300ba
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.40.0
2
+ * Add support for reading B3 single header.
3
+
1
4
  # 0.39.2
2
5
  * Make Faraday 0.13 the minimum requirement.
3
6
 
data/lib/zipkin-tracer.rb CHANGED
@@ -5,6 +5,7 @@ require 'zipkin-tracer/trace_client'
5
5
  require 'zipkin-tracer/trace_container'
6
6
  require 'zipkin-tracer/trace_generator'
7
7
  require 'zipkin-tracer/trace_wrapper'
8
+ require 'zipkin-tracer/zipkin_b3_single_header_format'
8
9
 
9
10
  begin
10
11
  require 'faraday'
@@ -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(@env['HTTP_X_B3_SAMPLED'])
15
- flags = (@env['HTTP_X_B3_FLAGS'] || default_flags).to_i
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
- B3_REQUIRED_HEADERS = %w(HTTP_X_B3_TRACEID HTTP_X_B3_SPANID).freeze
26
- B3_OPT_HEADERS = %w(HTTP_X_B3_PARENTSPANID HTTP_X_B3_SAMPLED HTTP_X_B3_FLAGS).freeze
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 called_with_zipkin_headers?
30
- trace_id, span_id = @env.values_at(*B3_REQUIRED_HEADERS)
31
- parent_span_id = @env['HTTP_X_B3_PARENTSPANID']
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
- else
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
- [trace_id, span_id, parent_span_id, shared]
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)
@@ -1,3 +1,3 @@
1
1
  module ZipkinTracer
2
- VERSION = '0.39.2'.freeze
2
+ VERSION = '0.40.0'.freeze
3
3
  end
@@ -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.39.2
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-08-26 00:00:00.000000000 Z
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