class ElasticAPM::TraceContext::Tracestate
@api private
Attributes
entries[RW]
Public Class Methods
new(entries: {}, sample_rate: nil)
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 95 def initialize(entries: {}, sample_rate: nil) @entries = entries self.sample_rate = sample_rate if sample_rate end
parse(header)
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 105 def self.parse(header) entries = split_by_nl_and_comma(header) .each_with_object({}) do |entry, hsh| k, v = entry.split('=') hsh[k] = case k when 'es' then EsEntry.new(v) else Entry.new(k, v) end end new(entries: entries) end
Private Class Methods
split_by_nl_and_comma(str)
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 137 def split_by_nl_and_comma(str) # HTTP allows multiple headers with the same name, eg. multiple # Set-Cookie headers per response. # Rack handles this by joining the headers under the same key, # separated by newlines. # See https://www.rubydoc.info/github/rack/rack/file/SPEC String(str).split("\n").map { |s| s.split(',') }.flatten end
Public Instance Methods
to_header()
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 121 def to_header return "" unless entries.any? entries.values.map(&:to_s).join(',') end
Private Instance Methods
es_entry()
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 129 def es_entry # lazy generate this so we only add it if necessary entries['es'] ||= EsEntry.new end