Class: Test::Span

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

Defined Under Namespace

Classes: LogEntry, SpanAlreadyFinished

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TypeCheck

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

Constructor Details

#initialize(tracer:, context:, operation_name:, start_time: Time.now, tags: nil) ⇒ Span

Returns a new instance of Span.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/test/span.rb', line 11

def initialize(tracer:, context:, operation_name:, start_time: Time.now, tags: nil)
  Type! tracer, ::Test::Tracer
  Type! context, ::Test::SpanContext
  Type! operation_name, String
  Type! start_time, Time
  Type! tags, Hash, NilClass

  @tracer = tracer
  @context = context
  @operation_name = operation_name
  @tags = tags || {}
  @logs = []
  @start_time = start_time
  @end_time = nil
  @in_progress = true
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



9
10
11
# File 'lib/test/span.rb', line 9

def end_time
  @end_time
end

#logsObject (readonly)

Returns the value of attribute logs.



9
10
11
# File 'lib/test/span.rb', line 9

def logs
  @logs
end

#operation_nameObject

Returns the value of attribute operation_name.



9
10
11
# File 'lib/test/span.rb', line 9

def operation_name
  @operation_name
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



9
10
11
# File 'lib/test/span.rb', line 9

def start_time
  @start_time
end

#tagsObject (readonly)

Returns the value of attribute tags.



9
10
11
# File 'lib/test/span.rb', line 9

def tags
  @tags
end

#tracerObject (readonly)

Returns the value of attribute tracer.



9
10
11
# File 'lib/test/span.rb', line 9

def tracer
  @tracer
end

Instance Method Details

#contextObject



38
39
40
# File 'lib/test/span.rb', line 38

def context
  @context
end

#finish(end_time: Time.now) ⇒ Object



79
80
81
82
83
84
85
86
87
# File 'lib/test/span.rb', line 79

def finish(end_time: Time.now)
  Type! end_time, Time
  ensure_in_progress!

  @end_time = end_time
  @in_progress = false
  @tracer.finished_spans << self
  self
end

#finished?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/test/span.rb', line 34

def finished?
  !in_progress?
end

#get_baggage_item(key) ⇒ Object



66
67
68
69
# File 'lib/test/span.rb', line 66

def get_baggage_item(key)
  Type! key, String
  @context.baggage[key]
end

#in_progress?Boolean Also known as: started?

Returns:

  • (Boolean)


28
29
30
# File 'lib/test/span.rb', line 28

def in_progress?
  @in_progress
end

#log(event: nil, timestamp: Time.now, **fields) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/test/span.rb', line 71

def log(event: nil, timestamp: Time.now, **fields)
  Type! event, String, NilClass
  Type! timestamp, Time
  ensure_in_progress!

  @logs << LogEntry.new(event, timestamp, fields)
end

#set_baggage_item(key, value) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/test/span.rb', line 57

def set_baggage_item(key, value)
  Type! key, String
  Type! value, String, NilClass
  ensure_in_progress!

  @context.baggage[key] = value.to_s
  self
end

#set_tag(key, value) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/test/span.rb', line 49

def set_tag(key, value)
  Type! key, String
  ensure_in_progress!

  @tags[key] = Type?(value, String, Fixnum, Bignum, Float, TrueClass, FalseClass) ? value : value.to_s
  self
end

#to_sObject



89
90
91
92
93
94
95
96
97
# File 'lib/test/span.rb', line 89

def to_s
  "Span(operation_name=#{operation_name}, " +
    "in_progress=#{in_progress?}, " +
    "tags=#{tags}, " +
    "logs=#{logs}, " +
    "start_time=#{start_time}, " +
    "end_time=#{end_time}, " +
    "context=#{context})"
end