Class: Atatus::TraceContext::Traceparent Private
- Inherits:
-
Object
- Object
- Atatus::TraceContext::Traceparent
- Defined in:
- lib/atatus/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'
- 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
rubocop:enable Metrics/ParameterLists.
-
#parent_id ⇒ Object
private
rubocop:enable Metrics/ParameterLists.
-
#recorded ⇒ Object
(also: #recorded?)
private
rubocop:enable Metrics/ParameterLists.
-
#trace_id ⇒ Object
private
rubocop:enable Metrics/ParameterLists.
-
#version ⇒ Object
private
rubocop:enable Metrics/ParameterLists.
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, span_id: nil, id: nil, recorded: true) ⇒ Traceparent
constructor
private
rubocop:disable Metrics/ParameterLists.
- #to_header ⇒ Object private
Constructor Details
#initialize(version: VERSION, trace_id: nil, span_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.
rubocop:disable Metrics/ParameterLists
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/atatus/trace_context/traceparent.rb', line 31 def initialize( version: VERSION, trace_id: nil, span_id: nil, id: nil, recorded: true ) @version = version @trace_id = trace_id || hex(TRACE_ID_LENGTH) # TODO: rename span_id kw arg to parent_id with next major version bump @parent_id = span_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.
rubocop:enable Metrics/ParameterLists
47 48 49 |
# File 'lib/atatus/trace_context/traceparent.rb', line 47 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.
rubocop:enable Metrics/ParameterLists
47 48 49 |
# File 'lib/atatus/trace_context/traceparent.rb', line 47 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.
rubocop:enable Metrics/ParameterLists
47 48 49 |
# File 'lib/atatus/trace_context/traceparent.rb', line 47 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.
rubocop:enable Metrics/ParameterLists
47 48 49 |
# File 'lib/atatus/trace_context/traceparent.rb', line 47 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.
rubocop:enable Metrics/ParameterLists
47 48 49 |
# File 'lib/atatus/trace_context/traceparent.rb', line 47 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/atatus/trace_context/traceparent.rb', line 51 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 HEX_REGEX =~ t.trace_id raise_invalid(header) if HEX_REGEX =~ 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.
93 94 95 96 97 98 |
# File 'lib/atatus/trace_context/traceparent.rb', line 93 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.
89 90 91 |
# File 'lib/atatus/trace_context/traceparent.rb', line 89 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.
81 82 83 |
# File 'lib/atatus/trace_context/traceparent.rb', line 81 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.
75 76 77 78 79 |
# File 'lib/atatus/trace_context/traceparent.rb', line 75 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.
85 86 87 |
# File 'lib/atatus/trace_context/traceparent.rb', line 85 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.
100 101 102 |
# File 'lib/atatus/trace_context/traceparent.rb', line 100 def to_header format('%s-%s-%s-%s', version, trace_id, id, hex_flags) end |