module Honeycomb::HoneycombPropagation::UnmarshalTraceContext

Parse trace headers

Public Class Methods

parse(serialized_trace) click to toggle source
# 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) click to toggle source
# File lib/honeycomb/propagation/honeycomb.rb, line 12
def parse_rack_env(env)
  parse env["HTTP_X_HONEYCOMB_TRACE"]
end
parse_v1(payload) click to toggle source
# 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

Public Instance Methods

parse(serialized_trace) click to toggle source
# 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) click to toggle source
# File lib/honeycomb/propagation/honeycomb.rb, line 12
def parse_rack_env(env)
  parse env["HTTP_X_HONEYCOMB_TRACE"]
end

Private Instance Methods

parse_v1(payload) click to toggle source
# 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