Class: ZipkinTracer::B3SingleHeaderFormat

Inherits:
Object
  • Object
show all
Defined in:
lib/zipkin-tracer/zipkin_b3_single_header_format.rb

Overview

This format corresponds to the propagation key “b3” (or “B3”). b3: x-b3-traceid-x-b3-spanid-x-b3-flags ‘d’ else x-b3-sampled-x-b3-parentspanid For details, see: github.com/openzipkin/b3-propagation

Constant Summary collapse

SAMPLED =
'1'
NOT_SAMPLED =
'0'
DEBUG =
'd'

Class Method Summary collapse

Class Method Details

.create_header(trace_id) ⇒ Object



32
33
34
35
36
# File 'lib/zipkin-tracer/zipkin_b3_single_header_format.rb', line 32

def self.create_header(trace_id)
  flag = trace_id.debug? ? DEBUG : (trace_id.sampled? ? SAMPLED : NOT_SAMPLED)
  parent_id_with_hyphen = "-#{trace_id.parent_id}" unless trace_id.parent_id.nil?
  "#{trace_id.trace_id}-#{trace_id.span_id}-#{flag}#{parent_id_with_hyphen}"
end

.parse_flags(flag) ⇒ Object



28
29
30
# File 'lib/zipkin-tracer/zipkin_b3_single_header_format.rb', line 28

def self.parse_flags(flag)
  flag == DEBUG ? Trace::Flags::DEBUG : Trace::Flags::EMPTY
end

.parse_from_header(b3_single_header) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/zipkin-tracer/zipkin_b3_single_header_format.rb', line 12

def self.parse_from_header(b3_single_header)
  if b3_single_header.size == 1
    flag = b3_single_header
  else
    trace_id, span_id, flag, parent_span_id = b3_single_header.split('-')
  end
  [trace_id, span_id, parent_span_id, parse_sampled(flag), parse_flags(flag)]
end

.parse_sampled(flag) ⇒ Object



21
22
23
24
25
26
# File 'lib/zipkin-tracer/zipkin_b3_single_header_format.rb', line 21

def self.parse_sampled(flag)
  case flag
  when SAMPLED, NOT_SAMPLED
    flag
  end
end