Class: Lenjador::Tracer::Span
- Inherits:
-
Object
- Object
- Lenjador::Tracer::Span
- Defined in:
- lib/lenjador/tracer/span.rb
Overview
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#operation_name ⇒ Object
writeonly
Sets the attribute operation_name.
Instance Method Summary collapse
-
#finish(end_time: Time.now) ⇒ Object
Finish the Span.
-
#get_baggage_item(key) ⇒ Object
Get a baggage item.
-
#initialize(context, operation_name, logger, start_time: Time.now, tags: {}) ⇒ Span
constructor
A new instance of Span.
-
#log(event: nil, timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span.
-
#log_kv(timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span.
-
#set_baggage_item(key, value) ⇒ Object
Set a baggage item on the span.
-
#set_tag(key, value) ⇒ Object
Set a tag value on this span.
-
#to_h ⇒ Object
deprecated
Deprecated.
This is not in OpenTracing API. It will be removed soon.
Constructor Details
#initialize(context, operation_name, logger, start_time: Time.now, tags: {}) ⇒ Span
Returns a new instance of Span.
9 10 11 12 13 14 15 16 |
# File 'lib/lenjador/tracer/span.rb', line 9 def initialize(context, operation_name, logger, start_time: Time.now, tags: {}) @context = context @operation_name = operation_name @logger = logger @start_time = start_time = @logger.info "Span [#{@operation_name}] started", trace_information end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
5 6 7 |
# File 'lib/lenjador/tracer/span.rb', line 5 def context @context end |
#operation_name=(value) ⇒ Object (writeonly)
Sets the attribute operation_name
7 8 9 |
# File 'lib/lenjador/tracer/span.rb', line 7 def operation_name=(value) @operation_name = value end |
Instance Method Details
#finish(end_time: Time.now) ⇒ Object
Finish the Lenjador::Tracer::Span
65 66 67 68 69 |
# File 'lib/lenjador/tracer/span.rb', line 65 def finish(end_time: Time.now) @logger.info "Span [#{@operation_name}] finished", trace_information( execution_time: end_time - @start_time ) end |
#get_baggage_item(key) ⇒ Object
Get a baggage item
40 41 42 |
# File 'lib/lenjador/tracer/span.rb', line 40 def get_baggage_item(key) nil end |
#log(event: nil, timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span
49 50 51 |
# File 'lib/lenjador/tracer/span.rb', line 49 def log(event: nil, timestamp: Time.now, **fields) @logger.info "Span [#{@operation_name}] #{event}", trace_information.merge(fields) end |
#log_kv(timestamp: Time.now, **fields) ⇒ Object
Add a log entry to this span
57 58 59 60 |
# File 'lib/lenjador/tracer/span.rb', line 57 def log_kv(timestamp: Time.now, **fields) event = fields.fetch(:event, 'unknown') @logger.info "Span [#{@operation_name}] #{event}", trace_information.merge(fields) end |
#set_baggage_item(key, value) ⇒ Object
Set a baggage item on the span
31 32 33 |
# File 'lib/lenjador/tracer/span.rb', line 31 def set_baggage_item(key, value) self end |
#set_tag(key, value) ⇒ Object
Set a tag value on this span
a String, Numeric, or Boolean it will be encoded with to_s
23 24 25 |
# File 'lib/lenjador/tracer/span.rb', line 23 def set_tag(key, value) = .merge(key => value) end |
#to_h ⇒ Object
Deprecated.
This is not in OpenTracing API. It will be removed soon.
72 73 74 |
# File 'lib/lenjador/tracer/span.rb', line 72 def to_h trace_information end |