Class: OpenTelemetry::DistributedContext::Propagation::TraceParent
- Inherits:
-
Object
- Object
- OpenTelemetry::DistributedContext::Propagation::TraceParent
- Defined in:
- lib/opentelemetry/distributed_context/propagation/trace_parent.rb
Overview
A TraceParent is an implementation of the W3C trace context specification www.w3.org/TR/trace-context/ Trace::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_context(ctx) ⇒ TraceParent
Creates a new TraceParent from a supplied Trace::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.
91 92 93 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 91 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
91 92 93 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 91 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
91 92 93 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 91 def trace_id @trace_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
91 92 93 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 91 def version @version end |
Class Method Details
.from_context(ctx) ⇒ TraceParent
Creates a new OpenTelemetry::DistributedContext::Propagation::TraceParent from a supplied Trace::SpanContext
31 32 33 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 31 def from_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::DistributedContext::Propagation::TraceParent from the string representation
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 42 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
97 98 99 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 97 def sampled? flags.sampled? end |
#to_s ⇒ String
converts this object into a string according to the w3c spec
103 104 105 |
# File 'lib/opentelemetry/distributed_context/propagation/trace_parent.rb', line 103 def to_s "00-#{trace_id}-#{span_id}-#{flag_string}" end |