class LightStep::SpanContext

SpanContext holds the data for a span that gets inherited to child spans

Constants

ZERO_PADDING

Attributes

baggage[R]
id[R]
sampled[R]
sampled?[R]
trace_id[R]
trace_id64[R]
trace_id_upper64[R]

Public Class Methods

new(id:, trace_id:, trace_id_upper64: nil, sampled: true, baggage: {}) click to toggle source
# File lib/lightstep/span_context.rb, line 12
def initialize(id:, trace_id:, trace_id_upper64: nil, sampled: true, baggage: {})
  @id = id.freeze
  @trace_id = truncate_id(trace_id).freeze
  @trace_id_upper64 = trace_id_upper64 || extended_bits(trace_id).freeze
  @sampled = sampled
  @baggage = baggage.freeze
end

Public Instance Methods

id_truncated?() click to toggle source

Returns true if the original trace_id was 128 bits

# File lib/lightstep/span_context.rb, line 26
def id_truncated?
  !@trace_id_upper64.nil?
end
trace_id128() click to toggle source

Lazily initializes and returns a 128-bit representation of a 64-bit trace id

# File lib/lightstep/span_context.rb, line 21
def trace_id128
  @trace_id128 ||= "#{trace_id_upper64 || ZERO_PADDING}#{trace_id}"
end

Private Instance Methods

extended_bits(id) click to toggle source

Returns the most significant 64 bits of a 128 bit id or nil if the id is 64 bits

# File lib/lightstep/span_context.rb, line 40
def extended_bits(id)
  return unless id && id.size == 32
  id[0...16]
end
truncate_id(id) click to toggle source

Truncates an id to 64 bits

# File lib/lightstep/span_context.rb, line 33
def truncate_id(id)
  return id unless id && id.size == 32
  id[16..-1]
end