Class: A2A::Monitoring::DistributedTracing::TraceContext
- Inherits:
-
Object
- Object
- A2A::Monitoring::DistributedTracing::TraceContext
- Defined in:
- lib/a2a/monitoring/distributed_tracing.rb
Overview
Trace context for distributed tracing
Instance Attribute Summary collapse
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#trace_flags ⇒ Object
readonly
Returns the value of attribute trace_flags.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#tracestate ⇒ Object
readonly
Returns the value of attribute tracestate.
Class Method Summary collapse
-
.parse(traceparent, tracestate = nil) ⇒ TraceContext?
Parse trace context from traceparent header.
Instance Method Summary collapse
-
#create_child ⇒ TraceContext
Create child context with new span ID.
-
#generate_span_id ⇒ String
private
Generate a new span ID.
-
#initialize(trace_id:, span_id:, trace_flags: 1, tracestate: nil) ⇒ TraceContext
constructor
Initialize trace context.
-
#to_traceparent ⇒ String
Convert to traceparent header format.
Constructor Details
#initialize(trace_id:, span_id:, trace_flags: 1, tracestate: nil) ⇒ TraceContext
Initialize trace context
148 149 150 151 152 153 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 148 def initialize(trace_id:, span_id:, trace_flags: 1, tracestate: nil) @trace_id = trace_id @span_id = span_id @trace_flags = trace_flags @tracestate = tracestate end |
Instance Attribute Details
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
139 140 141 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 139 def span_id @span_id end |
#trace_flags ⇒ Object (readonly)
Returns the value of attribute trace_flags.
139 140 141 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 139 def trace_flags @trace_flags end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
139 140 141 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 139 def trace_id @trace_id end |
#tracestate ⇒ Object (readonly)
Returns the value of attribute tracestate.
139 140 141 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 139 def tracestate @tracestate end |
Class Method Details
.parse(traceparent, tracestate = nil) ⇒ TraceContext?
Parse trace context from traceparent header
161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 161 def self.parse(traceparent, tracestate = nil) # Format: 00-{trace_id}-{span_id}-{trace_flags} parts = traceparent.split("-") return nil unless parts.size == 4 && parts[0] == "00" new( trace_id: parts[1], span_id: parts[2], trace_flags: parts[3].to_i(16), tracestate: tracestate ) rescue StandardError nil end |
Instance Method Details
#create_child ⇒ TraceContext
Create child context with new span ID
188 189 190 191 192 193 194 195 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 188 def create_child self.class.new( trace_id: @trace_id, span_id: generate_span_id, trace_flags: @trace_flags, tracestate: @tracestate ) end |
#generate_span_id ⇒ String (private)
Generate a new span ID
203 204 205 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 203 def generate_span_id SecureRandom.hex(8) end |
#to_traceparent ⇒ String
Convert to traceparent header format
180 181 182 |
# File 'lib/a2a/monitoring/distributed_tracing.rb', line 180 def to_traceparent "00-#{@trace_id}-#{@span_id}-#{@trace_flags.to_s(16).rjust(2, '0')}" end |