class Instana::SpanContext

Attributes

baggage[RW]
level[R]
span_id[RW]
trace_id[RW]

Public Class Methods

new(tid, sid, level = 1, baggage = {}) click to toggle source

Create a new SpanContext

@param tid [Integer] the trace ID @param sid [Integer] the span ID @param level [Integer] default 1 @param baggage [Hash] baggage applied to this trace

# File lib/instana/tracing/span_context.rb, line 18
def initialize(tid, sid, level = 1, baggage = {})
  @trace_id = tid
  @span_id = sid
  @level = Integer(level || 1)
  @baggage = baggage || {}
end

Public Instance Methods

active?() click to toggle source
# File lib/instana/tracing/span_context.rb, line 61
def active?
  @level == 1
end
span_id_header() click to toggle source
# File lib/instana/tracing/span_context.rb, line 29
def span_id_header
  ::Instana::Util.id_to_header(@span_id)
end
to_hash() click to toggle source
# File lib/instana/tracing/span_context.rb, line 53
def to_hash
  { :trace_id => @trace_id, :span_id => @span_id }
end
trace_id_header() click to toggle source
# File lib/instana/tracing/span_context.rb, line 25
def trace_id_header
  ::Instana::Util.id_to_header(@trace_id)
end
trace_parent_header() click to toggle source
# File lib/instana/tracing/span_context.rb, line 33
def trace_parent_header
  trace = (@baggage[:external_trace_id] || trace_id_header).rjust(32, '0')
  parent = span_id_header.rjust(16, '0')
  flags = @level == 1 ? "01" : "00"

  "00-#{trace}-#{parent}-#{flags}"
end
trace_state_header() click to toggle source
# File lib/instana/tracing/span_context.rb, line 41
def trace_state_header
  external_state = @baggage[:external_state] || ''
  state = external_state.split(/,/)

  if @level == 1
    state = state.reject { |s| s.start_with?('in=') }
    state.unshift("in=#{trace_id_header};#{span_id_header}")
  end

  state.reject { |v| v.nil? }.join(',')
end
valid?() click to toggle source
# File lib/instana/tracing/span_context.rb, line 57
def valid?
  @baggage && @trace_id && !@trace_id.emtpy?
end