Module: Honeycomb::HoneycombPropagation::UnmarshalTraceContext

Included in:
PropagationParser
Defined in:
lib/honeycomb/propagation/honeycomb.rb

Overview

Parse trace headers

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(serialized_trace) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/honeycomb/propagation/honeycomb.rb', line 16

def parse(serialized_trace)
  unless serialized_trace.nil?
    version, payload = serialized_trace.split(";", 2)

    if version == "1"
      trace_id, parent_span_id, trace_fields, dataset = parse_v1(payload)

      if !trace_id.nil? && !parent_span_id.nil?
        return [trace_id, parent_span_id, trace_fields, dataset]
      end
    end
  end

  [nil, nil, nil, nil]
end

.parse_rack_env(env) ⇒ Object



12
13
14
# File 'lib/honeycomb/propagation/honeycomb.rb', line 12

def parse_rack_env(env)
  parse env["HTTP_X_HONEYCOMB_TRACE"]
end

.parse_v1(payload) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/honeycomb/propagation/honeycomb.rb', line 32

def parse_v1(payload)
  trace_id, parent_span_id, trace_fields, dataset = nil
  payload.split(",").each do |entry|
    key, value = entry.split("=", 2)
    case key.downcase
    when "dataset"
      dataset = URI.decode_www_form_component(value)
    when "trace_id"
      trace_id = value
    when "parent_id"
      parent_span_id = value
    when "context"
      Base64.decode64(value).tap do |json|
        begin
          trace_fields = JSON.parse json
        rescue JSON::ParserError
          trace_fields = {}
        end
      end
    end
  end

  [trace_id, parent_span_id, trace_fields, dataset]
end

Instance Method Details

#parse(serialized_trace) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/honeycomb/propagation/honeycomb.rb', line 16

def parse(serialized_trace)
  unless serialized_trace.nil?
    version, payload = serialized_trace.split(";", 2)

    if version == "1"
      trace_id, parent_span_id, trace_fields, dataset = parse_v1(payload)

      if !trace_id.nil? && !parent_span_id.nil?
        return [trace_id, parent_span_id, trace_fields, dataset]
      end
    end
  end

  [nil, nil, nil, nil]
end

#parse_rack_env(env) ⇒ Object



12
13
14
# File 'lib/honeycomb/propagation/honeycomb.rb', line 12

def parse_rack_env(env)
  parse env["HTTP_X_HONEYCOMB_TRACE"]
end