Class: ElasticAPM::TraceContext::Tracestate Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elastic_apm/trace_context/tracestate.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

API:

  • private

Defined Under Namespace

Classes: Entry, EsEntry

Constant Summary collapse

ENTRY_SPLIT_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

/\s*[\n,]+\s*/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entries: {}, sample_rate: nil) ⇒ Tracestate

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Tracestate.

API:

  • private



97
98
99
100
101
# 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

Instance Attribute Details

#entriesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



103
104
105
# File 'lib/elastic_apm/trace_context/tracestate.rb', line 103

def entries
  @entries
end

Class Method Details

.parse(header) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# 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

Instance Method Details

#to_headerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



123
124
125
126
127
# File 'lib/elastic_apm/trace_context/tracestate.rb', line 123

def to_header
  return "" unless entries.any?

  entries.values.map(&:to_s).join(',')
end