class Atatus::TraceContext::Traceparent
@api private
Constants
- HEX_REGEX
- ID_LENGTH
- TRACE_ID_LENGTH
- VERSION
Attributes
id[RW]
rubocop:enable Metrics/ParameterLists
parent_id[RW]
rubocop:enable Metrics/ParameterLists
recorded[RW]
rubocop:enable Metrics/ParameterLists
recorded?[RW]
rubocop:enable Metrics/ParameterLists
trace_id[RW]
rubocop:enable Metrics/ParameterLists
version[RW]
rubocop:enable Metrics/ParameterLists
Public Class Methods
new( version: VERSION, trace_id: nil, span_id: nil, id: nil, recorded: true )
click to toggle source
rubocop:disable Metrics/ParameterLists
# 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
parse(header)
click to toggle source
# 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
Private Class Methods
raise_invalid(header)
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 69 def raise_invalid(header) raise InvalidTraceparentHeader, "Couldn't parse invalid traceparent header: #{header.inspect}" end
Public Instance Methods
child()
click to toggle source
# 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()
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 89 def ensure_parent_id @parent_id ||= hex(ID_LENGTH) end
flags()
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 81 def flags format('0000000%d', recorded? ? 1 : 0) end
flags=(flags)
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 75 def flags=(flags) @flags = flags self.recorded = flags[7] == '1' end
hex_flags()
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 85 def hex_flags format('%02x', flags.to_i(2)) end
to_header()
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 100 def to_header format('%s-%s-%s-%s', version, trace_id, id, hex_flags) end
Private Instance Methods
hex(len)
click to toggle source
# File lib/atatus/trace_context/traceparent.rb, line 106 def hex(len) SecureRandom.hex(len) end