Module: Honeycomb::HoneycombModernPropagation::UnmarshalTraceContext
- Defined in:
- lib/honeycomb/propagation/honeycomb_modern.rb
Overview
Parse trace headers
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.parse(serialized_trace) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 17 def parse(serialized_trace) unless serialized_trace.nil? version, payload = serialized_trace.split(";", 2) if version == "1" trace_id, parent_span_id, trace_fields = parse_v1(payload) if !trace_id.nil? && !parent_span_id.nil? return [trace_id, parent_span_id, trace_fields, nil] end end end [nil, nil, nil, nil] end |
.parse_rack_env(env) ⇒ Object
13 14 15 |
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 13 def parse_rack_env(env) parse env["HTTP_X_HONEYCOMB_TRACE"] end |
.parse_v1(payload) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 33 def parse_v1(payload) trace_id, parent_span_id, trace_fields = nil payload.split(",").each do |entry| key, value = entry.split("=", 2) case key.downcase when "trace_id" trace_id = value when "parent_id" parent_span_id = value when "context" Base64.urlsafe_decode64(value).tap do |json| trace_fields = JSON.parse json rescue JSON::ParserError trace_fields = {} end end end [trace_id, parent_span_id, trace_fields, nil] end |
Instance Method Details
#parse(serialized_trace) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 17 def parse(serialized_trace) unless serialized_trace.nil? version, payload = serialized_trace.split(";", 2) if version == "1" trace_id, parent_span_id, trace_fields = parse_v1(payload) if !trace_id.nil? && !parent_span_id.nil? return [trace_id, parent_span_id, trace_fields, nil] end end end [nil, nil, nil, nil] end |
#parse_rack_env(env) ⇒ Object
13 14 15 |
# File 'lib/honeycomb/propagation/honeycomb_modern.rb', line 13 def parse_rack_env(env) parse env["HTTP_X_HONEYCOMB_TRACE"] end |