Class: ElasticAPM::TraceContext::Traceparent Private
- Inherits:
-
Object
- Object
- ElasticAPM::TraceContext::Traceparent
- Defined in:
- lib/elastic_apm/trace_context/traceparent.rb
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.
Constant Summary collapse
- VERSION =
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.
'00'
- NON_HEX_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.
/[^[:xdigit:]]/.freeze
- TRACE_ID_LENGTH =
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.
16
- ID_LENGTH =
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.
8
Instance Attribute Summary collapse
- #id ⇒ Object private
- #parent_id ⇒ Object private
- #recorded ⇒ Object (also: #recorded?) private
- #trace_id ⇒ Object private
- #version ⇒ Object private
Class Method Summary collapse
- .parse(header) ⇒ Object private
Instance Method Summary collapse
- #child ⇒ Object private
- #ensure_parent_id ⇒ Object private
- #flags ⇒ Object private
- #flags=(flags) ⇒ Object private
- #hex_flags ⇒ Object private
-
#initialize(version: VERSION, trace_id: nil, parent_id: nil, id: nil, recorded: true) ⇒ Traceparent
constructor
private
A new instance of Traceparent.
- #to_header ⇒ Object private
Constructor Details
#initialize(version: VERSION, trace_id: nil, parent_id: nil, id: nil, recorded: true) ⇒ Traceparent
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 Traceparent.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 30 def initialize( version: VERSION, trace_id: nil, parent_id: nil, id: nil, recorded: true ) @version = version @trace_id = trace_id || hex(TRACE_ID_LENGTH) @parent_id = parent_id @id = id || hex(ID_LENGTH) @recorded = recorded end |
Instance Attribute Details
#id ⇒ 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.
44 45 46 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 44 def id @id end |
#parent_id ⇒ 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.
44 45 46 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 44 def parent_id @parent_id end |
#recorded ⇒ Object Also known as: recorded?
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.
44 45 46 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 44 def recorded @recorded end |
#trace_id ⇒ 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.
44 45 46 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 44 def trace_id @trace_id end |
#version ⇒ 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.
44 45 46 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 44 def version @version 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 48 def self.parse(header) raise_invalid(header) unless header.length == 55 raise_invalid(header) unless header[0..1] == VERSION new.tap do |t| t.version, t.trace_id, t.parent_id, t.flags = header.split('-').tap do |values| values[-1] = Util.hex_to_bits(values[-1]) end raise_invalid(header) if NON_HEX_REGEX.match?(t.trace_id) raise_invalid(header) if NON_HEX_REGEX.match?(t.parent_id) end end |
Instance Method Details
#child ⇒ 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.
90 91 92 93 94 95 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 90 def child dup.tap do |copy| copy.parent_id = id copy.id = hex(ID_LENGTH) end end |
#ensure_parent_id ⇒ 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.
86 87 88 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 86 def ensure_parent_id @parent_id ||= hex(ID_LENGTH) end |
#flags ⇒ 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.
78 79 80 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 78 def flags format('0000000%d', recorded? ? 1 : 0) end |
#flags=(flags) ⇒ 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.
72 73 74 75 76 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 72 def flags=(flags) @flags = flags self.recorded = flags[7] == '1' end |
#hex_flags ⇒ 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.
82 83 84 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 82 def hex_flags format('%02x', flags.to_i(2)) end |
#to_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.
97 98 99 |
# File 'lib/elastic_apm/trace_context/traceparent.rb', line 97 def to_header format('%s-%s-%s-%s', version, trace_id, id, hex_flags) end |