Class: Test::Span
- Inherits:
-
OpenTracing::Span
- Object
- OpenTracing::Span
- Test::Span
- Includes:
- TypeCheck
- Defined in:
- lib/test/span.rb
Defined Under Namespace
Classes: LogEntry, SpanAlreadyFinished
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#logs ⇒ Object
readonly
Returns the value of attribute logs.
-
#operation_name ⇒ Object
Returns the value of attribute operation_name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
-
#tracer ⇒ Object
readonly
Returns the value of attribute tracer.
Instance Method Summary collapse
- #context ⇒ Object
- #finish(end_time: Time.now) ⇒ Object
- #finished? ⇒ Boolean
- #get_baggage_item(key) ⇒ Object
- #in_progress? ⇒ Boolean (also: #started?)
-
#initialize(tracer:, context:, operation_name:, start_time: Time.now, tags: nil) ⇒ Span
constructor
A new instance of Span.
- #log(event: nil, timestamp: Time.now, **fields) ⇒ Object
- #set_baggage_item(key, value) ⇒ Object
- #set_tag(key, value) ⇒ Object
- #to_s ⇒ Object
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! , Hash, NilClass @tracer = tracer @context = context @operation_name = operation_name @tags = || {} @logs = [] @start_time = start_time @end_time = nil @in_progress = true end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
9 10 11 |
# File 'lib/test/span.rb', line 9 def end_time @end_time end |
#logs ⇒ Object (readonly)
Returns the value of attribute logs.
9 10 11 |
# File 'lib/test/span.rb', line 9 def logs @logs end |
#operation_name ⇒ Object
Returns the value of attribute operation_name.
9 10 11 |
# File 'lib/test/span.rb', line 9 def operation_name @operation_name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
9 10 11 |
# File 'lib/test/span.rb', line 9 def start_time @start_time end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
9 10 11 |
# File 'lib/test/span.rb', line 9 def @tags end |
#tracer ⇒ Object (readonly)
Returns the value of attribute tracer.
9 10 11 |
# File 'lib/test/span.rb', line 9 def tracer @tracer end |
Instance Method Details
#context ⇒ Object
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
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?
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! , Time ensure_in_progress! @logs << LogEntry.new(event, , 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_s ⇒ Object
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=#{}, " + "logs=#{logs}, " + "start_time=#{start_time}, " + "end_time=#{end_time}, " + "context=#{context})" end |