Class: OpenTelemetry::Propagator::GoogleCloudTraceContext::CloudTraceContext
- Inherits:
-
Object
- Object
- OpenTelemetry::Propagator::GoogleCloudTraceContext::CloudTraceContext
- Defined in:
- lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb
Overview
Provides a class for decoding and encoding x-cloud-trace-context header to/from into trace components
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.
Class Method Summary collapse
-
.from_span_context(ctx) ⇒ CloudTraceContext
Creates a new CloudTraceContext from a supplied Trace::SpanContext.
-
.from_string(string) ⇒ CloudTraceContext?
Deserializes the CloudTraceContext from the string representation.
Instance Method Summary collapse
-
#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.
47 48 49 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 47 def flags @flags end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
47 48 49 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 47 def span_id @span_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
47 48 49 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 47 def trace_id @trace_id end |
Class Method Details
.from_span_context(ctx) ⇒ CloudTraceContext
Creates a new OpenTelemetry::Propagator::GoogleCloudTraceContext::CloudTraceContext from a supplied Trace::SpanContext
28 29 30 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 28 def from_span_context(ctx) new(trace_id: ctx.trace_id, span_id: ctx.span_id, flags: ctx.trace_flags) end |
.from_string(string) ⇒ CloudTraceContext?
Deserializes the OpenTelemetry::Propagator::GoogleCloudTraceContext::CloudTraceContext from the string representation
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 35 def from_string(string) matches = CLOUD_TRACE_CONTEXT_REGEX.match(string) return unless matches trace_id = Array(matches[:trace_id].downcase).pack('H*') span_id = Array(matches[:span_id].to_i.to_s(16)).pack('H*') flags = matches[:options] == '1' ? Trace::TraceFlags::SAMPLED : Trace::TraceFlags::DEFAULT new(trace_id: trace_id, span_id: span_id, flags: flags) end |
Instance Method Details
#to_s ⇒ String
converts this object into a string according to the w3c spec
53 54 55 |
# File 'lib/opentelemetry/propagator/google_cloud_trace_context/text_map_propagator.rb', line 53 def to_s "#{trace_id.unpack1('H*')}/#{span_id.unpack1('H*').to_i(16)};o=#{flags.sampled? ? '1' : '0'}" end |