lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb in opentelemetry-api-0.4.0 vs lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb in opentelemetry-api-0.5.0

- old
+ new

@@ -23,10 +23,14 @@ private_constant :MAX_VERSION REGEXP = /^(?<version>[A-Fa-f0-9]{2})-(?<trace_id>[A-Fa-f0-9]{32})-(?<span_id>[A-Fa-f0-9]{16})-(?<flags>[A-Fa-f0-9]{2})(?<ignored>-.*)?$/.freeze private_constant :REGEXP + INVALID_TRACE_ID = OpenTelemetry::Trace::INVALID_TRACE_ID.unpack1('H*') + INVALID_SPAN_ID = OpenTelemetry::Trace::INVALID_SPAN_ID.unpack1('H*') + private_constant :INVALID_TRACE_ID, :INVALID_SPAN_ID + class << self # Creates a new {TraceParent} from a supplied {Trace::SpanContext} # @param [SpanContext] ctx The context # @return [TraceParent] a trace parent def from_context(ctx) @@ -69,21 +73,21 @@ v end def parse_trace_id(string) - raise InvalidTraceIDError, string if string == OpenTelemetry::Trace::INVALID_TRACE_ID + raise InvalidTraceIDError, string if string == INVALID_TRACE_ID string.downcase! - string + Array(string).pack('H*') end def parse_span_id(string) - raise InvalidSpanIDError, string if string == OpenTelemetry::Trace::INVALID_SPAN_ID + raise InvalidSpanIDError, string if string == INVALID_SPAN_ID string.downcase! - string + Array(string).pack('H*') end def parse_flags(string) OpenTelemetry::Trace::TraceFlags.from_byte(string.to_i(16)) end @@ -100,10 +104,10 @@ end # converts this object into a string according to the w3c spec # @return [String] the serialized trace_parent def to_s - "00-#{trace_id}-#{span_id}-#{flag_string}" + "00-#{trace_id.unpack1('H*')}-#{span_id.unpack1('H*')}-#{flag_string}" end private def flag_string