Module: Honeycomb::HoneycombModernPropagation::MarshalTraceContext

Includes:
Libhoney::Cleaner
Defined in:
lib/honeycomb/propagation/honeycomb_modern.rb

Overview

Serialize trace headers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean_dataObject

.clean_stringObject

.encode_trace_fields(fields) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 89

def encode_trace_fields(fields)
  Base64.urlsafe_encode64(
    JSON.generate(
      clean_data(fields),
    ),
  ).strip
end

.parse_faraday_env(_env, propagation_context) ⇒ Object



74
75
76
77
78
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 74

def self.parse_faraday_env(_env, propagation_context)
  {
    "X-Honeycomb-Trace" => to_trace_header(propagation_context),
  }
end

.to_trace_header(propagation_context) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 80

def self.to_trace_header(propagation_context)
  data_to_propogate = [
    "trace_id=#{propagation_context.trace_id}",
    "parent_id=#{propagation_context.parent_id}",
    "context=#{encode_trace_fields(propagation_context.trace_fields)}",
  ]
  "1;#{data_to_propogate.join(',')}"
end

Instance Method Details

#to_trace_headerObject



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

def to_trace_header
  data_to_propogate = [
    "trace_id=#{trace.id}",
    "parent_id=#{id}",
    "context=#{encode_trace_fields(trace.fields)}",
  ]
  "1;#{data_to_propogate.join(',')}"
end