Class: Jaeger::Client::SpanContext

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

Overview

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

Defined Under Namespace

Modules: Flags

Constant Summary collapse

MAX_SIGNED_ID =
(1 << 63) - 1
MAX_UNSIGNED_ID =
(1 << 64)
ID_ATTRIBUTES =
i[span_id parent_id trace_id].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(span_id:, parent_id: 0, trace_id:, flags:, baggage: {}) ⇒ SpanContext

Returns a new instance of SpanContext.



40
41
42
43
44
45
46
# File 'lib/jaeger/client/span_context.rb', line 40

def initialize(span_id:, parent_id: 0, trace_id:, flags:, baggage: {})
  @span_id = span_id
  @parent_id = parent_id
  @trace_id = trace_id
  @baggage = baggage
  @flags = flags
end

Class Method Details

.create_from_parent_context(span_context) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/jaeger/client/span_context.rb', line 24

def self.create_from_parent_context(span_context)
  trace_id = span_context.trace_id
  parent_id = span_context.span_id
  flags = span_context.flags
  span_id = TraceId.generate
  new(span_id: span_id, parent_id: parent_id, trace_id: trace_id, flags: flags)
end

.create_parent_context(sampler = Samplers::Const.new(true)) ⇒ Object



17
18
19
20
21
22
# File 'lib/jaeger/client/span_context.rb', line 17

def self.create_parent_context(sampler = Samplers::Const.new(true))
  trace_id = TraceId.generate
  span_id = TraceId.generate
  flags = sampler.sample?(trace_id) ? Flags::SAMPLED : Flags::NONE
  new(trace_id: trace_id, span_id: span_id, flags: flags)
end

Instance Method Details

#debug?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/jaeger/client/span_context.rb', line 52

def debug?
  @flags & Flags::DEBUG == Flags::DEBUG
end

#inspectObject



56
57
58
# File 'lib/jaeger/client/span_context.rb', line 56

def inspect
  to_s
end

#sampled?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/jaeger/client/span_context.rb', line 48

def sampled?
  @flags & Flags::SAMPLED == Flags::SAMPLED
end

#to_sObject



60
61
62
63
64
65
# File 'lib/jaeger/client/span_context.rb', line 60

def to_s
  "#<SpanContext @span_id=#{span_id.to_s(16)} " \
    "@parent_id=#{parent_id.to_s(16)} " \
    "@trace_id=#{trace_id.to_s(16)} " \
    "@flags=#{flags}>"
end