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

Instance Attribute Summary collapse

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.



30
31
32
33
34
35
36
# File 'lib/jaeger/client/span_context.rb', line 30

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

Instance Attribute Details

#baggageObject (readonly)

Returns the value of attribute baggage.



28
29
30
# File 'lib/jaeger/client/span_context.rb', line 28

def baggage
  @baggage
end

#flagsObject (readonly)

Returns the value of attribute flags.



28
29
30
# File 'lib/jaeger/client/span_context.rb', line 28

def flags
  @flags
end

#parent_idObject (readonly)

Returns the value of attribute parent_id.



28
29
30
# File 'lib/jaeger/client/span_context.rb', line 28

def parent_id
  @parent_id
end

#span_idObject (readonly)

Returns the value of attribute span_id.



28
29
30
# File 'lib/jaeger/client/span_context.rb', line 28

def span_id
  @span_id
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



28
29
30
# File 'lib/jaeger/client/span_context.rb', line 28

def trace_id
  @trace_id
end

Class Method Details

.create_from_parent_context(span_context) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/jaeger/client/span_context.rb', line 20

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



13
14
15
16
17
18
# File 'lib/jaeger/client/span_context.rb', line 13

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)


42
43
44
# File 'lib/jaeger/client/span_context.rb', line 42

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

#sampled?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/jaeger/client/span_context.rb', line 38

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

#to_parent_idObject



50
51
52
# File 'lib/jaeger/client/span_context.rb', line 50

def to_parent_id
  @to_parent_id ||= @parent_id.zero? ? nil : @parent_id.to_s(16)
end

#to_span_idObject



54
55
56
# File 'lib/jaeger/client/span_context.rb', line 54

def to_span_id
  @to_span_id ||= @span_id.to_s(16)
end

#to_trace_idObject



46
47
48
# File 'lib/jaeger/client/span_context.rb', line 46

def to_trace_id
  @to_trace_id ||= @trace_id.to_s(16)
end