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 =
rubocop:disable Style/EmptyClassDefinition
Class.new(Error)
- InvalidVersionError =
Class.new(Error)
- InvalidTraceIDError =
Class.new(Error)
- InvalidSpanIDError =
Class.new(Error)
- TRACE_PARENT_HEADER =
rubocop:enable Style/EmptyClassDefinition
'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.
98 99 100 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 98 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
98 99 100 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 98 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
98 99 100 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 98 def trace_id @trace_id end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
98 99 100 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 98 def version @version end |
Class Method Details
.from_span_context(ctx) ⇒ TraceParent
Creates a new OpenTelemetry::Trace::Propagation::TraceContext::TraceParent from a supplied SpanContext
38 39 40 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 38 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
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 49 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
104 105 106 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 104 def sampled? flags.sampled? end |
#to_s ⇒ String
converts this object into a string according to the w3c spec
110 111 112 |
# File 'lib/opentelemetry/trace/propagation/trace_context/trace_parent.rb', line 110 def to_s "00-#{trace_id.unpack1('H*')}-#{span_id.unpack1('H*')}-#{flag_string}" end |