Module: Honeycomb::W3CPropagation::MarshalTraceContext

Defined in:
lib/honeycomb/propagation/w3c.rb

Overview

Serialize trace headers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_faraday_env(_env, propagation_context) ⇒ Object



57
58
59
60
61
# File 'lib/honeycomb/propagation/w3c.rb', line 57

def self.parse_faraday_env(_env, propagation_context)
  {
    "traceparent" => to_trace_header(propagation_context),
  }
end

.to_trace_header(propagation_context) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/honeycomb/propagation/w3c.rb', line 63

def self.to_trace_header(propagation_context)
  trace_id = propagation_context.trace_id
  parent_id = propagation_context.parent_id
  # do not propagate malformed ids
  if trace_id =~ /^[A-Fa-f0-9]{32}$/ && parent_id =~ /^[A-Fa-f0-9]{16}$/
    return "00-#{trace_id}-#{parent_id}-01"
  end

  nil
end

Instance Method Details

#to_trace_headerObject



48
49
50
51
52
53
54
55
# File 'lib/honeycomb/propagation/w3c.rb', line 48

def to_trace_header
  # do not propagate malformed ids
  if trace.id =~ /^[A-Fa-f0-9]{32}$/ && id =~ /^[A-Fa-f0-9]{16}$/
    return "00-#{trace.id}-#{id}-01"
  end

  nil
end