Class: Test::SpanContext

Inherits:
OpenTracing::SpanContext
  • Object
show all
Includes:
TypeCheck
Defined in:
lib/test/span_context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TypeCheck

#Argument!, #NotNull!, #Type!, #Type?

Constructor Details

#initialize(trace_id:, span_id:, parent_span_id: nil, baggage: {}) ⇒ SpanContext

Returns a new instance of SpanContext.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/test/span_context.rb', line 21

def initialize(trace_id:, span_id:, parent_span_id: nil, baggage: {})
  Type! trace_id, String
  Type! span_id, String
  Type! parent_span_id, String, NilClass
  Type! baggage, Hash

  super(baggage: baggage)

  @trace_id = trace_id
  @span_id = span_id
  @parent_span_id = parent_span_id
  @baggage = baggage
end

Instance Attribute Details

#parent_span_idObject (readonly)

Returns the value of attribute parent_span_id.



19
20
21
# File 'lib/test/span_context.rb', line 19

def parent_span_id
  @parent_span_id
end

#span_idObject (readonly)

Returns the value of attribute span_id.



19
20
21
# File 'lib/test/span_context.rb', line 19

def span_id
  @span_id
end

#trace_idObject (readonly)

Returns the value of attribute trace_id.



19
20
21
# File 'lib/test/span_context.rb', line 19

def trace_id
  @trace_id
end

Class Method Details

.child_of(parent_context) ⇒ Object



9
10
11
12
13
14
# File 'lib/test/span_context.rb', line 9

def child_of(parent_context)
  new(trace_id: parent_context.trace_id,
      span_id: IdProvider.generate,
      parent_span_id: parent_context.span_id,
      baggage: parent_context.baggage)
end

.rootObject



4
5
6
7
# File 'lib/test/span_context.rb', line 4

def root
  new(trace_id: IdProvider.generate,
      span_id: IdProvider.generate)
end

Instance Method Details

#==(rhs) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/test/span_context.rb', line 39

def ==(rhs)
  self.class == rhs.class &&
    trace_id == rhs.trace_id &&
    span_id == rhs.span_id &&
    parent_span_id == rhs.parent_span_id &&
    baggage == rhs.baggage
end

#to_sObject



35
36
37
# File 'lib/test/span_context.rb', line 35

def to_s
  "SpanContext(trace_id=#{trace_id}, span_id=#{span_id}, parent_span_id=#{parent_span_id}, baggage=#{baggage})"
end