Class: OpenTelemetry::Trace::Propagation::TraceContext::TraceParent
- Inherits:
-
Object
- Object
- OpenTelemetry::Trace::Propagation::TraceContext::TraceParent
- Defined in:
- lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb
Overview
A TraceParent is an implementation of the W3C trace context specification www.w3.org/TR/trace-context/ SpanContext
Constant Summary collapse
- InvalidFormatError =
Class.new(Error)
- InvalidVersionError =
Class.new(Error)
- InvalidTraceIDError =
Class.new(Error)
- InvalidSpanIDError =
Class.new(Error)
- TRACE_PARENT_HEADER =
'traceparent'
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
-
.from_span_context(ctx) ⇒ TraceParent
Creates a new TraceParent from a supplied SpanContext.
-
.from_string(string) ⇒ TraceParent
Deserializes the TraceParent from the string representation.
Instance Method Summary collapse
-
#sampled? ⇒ Boolean
Returns the sampling choice from the trace_flags.
-
#to_s ⇒ String
converts this object into a string according to the w3c spec.
Instance Attribute Details
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
96 97 98 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 96 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
96 97 98 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 96 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
96 97 98 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 96 def trace_id @trace_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
96 97 98 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 96 def version @version end |
Class Method Details
.from_span_context(ctx) ⇒ TraceParent
Creates a new OpenTelemetry::Trace::Propagation::TraceContext::TraceParent from a supplied SpanContext
36 37 38 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 36 def from_span_context(ctx) new(trace_id: ctx.trace_id, span_id: ctx.span_id, flags: ctx.trace_flags) end |
.from_string(string) ⇒ TraceParent
Deserializes the OpenTelemetry::Trace::Propagation::TraceContext::TraceParent from the string representation
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 47 def from_string(string) matches = match_input(string) version = parse_version(matches[:version]) raise InvalidFormatError if version > SUPPORTED_VERSION && string.length < 55 trace_id = parse_trace_id(matches[:trace_id]) span_id = parse_span_id(matches[:span_id]) flags = parse_flags(matches[:flags]) new(trace_id: trace_id, span_id: span_id, flags: flags) end |
Instance Method Details
#sampled? ⇒ Boolean
Returns the sampling choice from the trace_flags
102 103 104 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 102 def sampled? flags.sampled? end |
#to_s ⇒ String
converts this object into a string according to the w3c spec
108 109 110 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 108 def to_s "00-#{trace_id.unpack1('H*')}-#{span_id.unpack1('H*')}-#{flag_string}" end |