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 https://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_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.
92 93 94 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 92 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
92 93 94 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 92 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
92 93 94 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 92 def trace_id @trace_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
92 93 94 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 92 def version @version end |
Class Method Details
.from_context(ctx) ⇒ TraceParent
Creates a new OpenTelemetry::Trace::Propagation::TraceContext::TraceParent from a supplied SpanContext
32 33 34 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 32 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::Trace::Propagation::TraceContext::TraceParent from the string representation
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 43 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
98 99 100 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 98 def sampled? flags.sampled? end |
#to_s ⇒ String
converts this object into a string according to the w3c spec
104 105 106 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 104 def to_s "00-#{trace_id}-#{span_id}-#{flag_string}" end |