Class: LightStep::SpanContext

Inherits:
Object
  • Object
show all
Defined in:
lib/lightstep/span_context.rb

Overview

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

Constant Summary collapse

ZERO_PADDING =
'0' * 16

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, trace_id:, trace_id_upper64: nil, sampled: true, baggage: {}) ⇒ SpanContext

Returns a new instance of SpanContext.



12
13
14
15
16
17
18
# 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

Instance Attribute Details

#baggageObject (readonly)

Returns the value of attribute baggage.



6
7
8
# File 'lib/lightstep/span_context.rb', line 6

def baggage
  @baggage
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/lightstep/span_context.rb', line 6

def id
  @id
end

#sampledObject (readonly) Also known as: sampled?

Returns the value of attribute sampled.



6
7
8
# File 'lib/lightstep/span_context.rb', line 6

def sampled
  @sampled
end

#trace_idObject (readonly) Also known as: trace_id64

Returns the value of attribute trace_id.



6
7
8
# File 'lib/lightstep/span_context.rb', line 6

def trace_id
  @trace_id
end

#trace_id_upper64Object (readonly)

Returns the value of attribute trace_id_upper64.



6
7
8
# File 'lib/lightstep/span_context.rb', line 6

def trace_id_upper64
  @trace_id_upper64
end

Instance Method Details

#id_truncated?Boolean

Returns true if the original trace_id was 128 bits

Returns:

  • (Boolean)


26
27
28
# File 'lib/lightstep/span_context.rb', line 26

def id_truncated?
  !@trace_id_upper64.nil?
end

#trace_id128Object

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



21
22
23
# File 'lib/lightstep/span_context.rb', line 21

def trace_id128
  @trace_id128 ||= "#{trace_id_upper64 || ZERO_PADDING}#{trace_id}"
end