class ElasticAPM::TraceContext::Tracestate
@api private
Constants
- ENTRY_SPLIT_REGEX
Attributes
entries[RW]
Public Class Methods
new(entries: {}, sample_rate: nil)
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 97 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 107 def self.parse(header) entries = split_by_nl_and_comma(header) .each_with_object({}) do |entry, hsh| k, v = entry.split('=') next unless k && v && !k.empty? && !v.empty? 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 139 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(ENTRY_SPLIT_REGEX).flatten end
Public Instance Methods
to_header()
click to toggle source
# File lib/elastic_apm/trace_context/tracestate.rb, line 123 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 131 def es_entry # lazy generate this so we only add it if necessary entries['es'] ||= EsEntry.new end