Class: OpenTelemetry::Trace::Span
- Inherits:
-
Object
- Object
- OpenTelemetry::Trace::Span
- Defined in:
- lib/opentelemetry/trace/span.rb
Overview
Span represents a single operation within a trace. Spans can be nested to form a trace tree. Often, a trace contains a root span that describes the end-to-end latency and, optionally, one or more sub-spans for its sub-operations.
Once Span is created - Span operations can be used to add additional properties to it like attributes, links, events, name and resulting status. Span cannot be used to retrieve these properties. This prevents the mis-use of spans as an in-process information propagation mechanism.
Constant Summary collapse
- INVALID =
new(span_context: SpanContext::INVALID)
Instance Attribute Summary collapse
-
#context ⇒ SpanContext
readonly
Retrieve the spans SpanContext.
Instance Method Summary collapse
-
#add_event(name: nil, attributes: nil, timestamp: nil) ⇒ self
Add an Event to a Span.
-
#finish(end_timestamp: nil) ⇒ self
Finishes the Span.
-
#initialize(span_context: nil) ⇒ Span
constructor
private
Spans must be created using Tracer.
-
#name=(new_name) ⇒ void
Updates the Span name.
-
#recording? ⇒ Boolean
Return whether this span is recording.
-
#set_attribute(key, value) ⇒ self
(also: #[]=)
Set attribute.
-
#status=(status) ⇒ void
Sets the Status to the Span.
Constructor Details
#initialize(span_context: nil) ⇒ Span
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Spans must be created using Tracer. This is for internal use only.
32 33 34 |
# File 'lib/opentelemetry/trace/span.rb', line 32 def initialize(span_context: nil) @context = span_context || SpanContext.new end |
Instance Attribute Details
#context ⇒ SpanContext (readonly)
Retrieve the spans SpanContext
The returned value may be used even after the Span is finished.
27 28 29 |
# File 'lib/opentelemetry/trace/span.rb', line 27 def context @context end |
Instance Method Details
#add_event(name: nil, attributes: nil, timestamp: nil) ⇒ self
Add an Event to a OpenTelemetry::Trace::Span. This can be accomplished eagerly or lazily. Lazy evaluation is useful when the event attributes are expensive to build and where the cost can be avoided for an unsampled OpenTelemetry::Trace::Span.
Eager example:
span.add_event(name: 'event', attributes: {'eager' => true})
Lazy example:
span.add_event { tracer.create_event(name: 'event', attributes: {'eager' => false}) }
Note that the OpenTelemetry project documents certain “standard event names and keys” which have prescribed semantic meanings.
88 89 90 |
# File 'lib/opentelemetry/trace/span.rb', line 88 def add_event(name: nil, attributes: nil, timestamp: nil) self end |
#finish(end_timestamp: nil) ⇒ self
Finishes the Span
Implementations MUST ignore all subsequent calls to #finish (there might be exceptions when Tracer is streaming event and has no mutable state associated with the Span).
Call to #finish MUST not have any effects on child spans. Those may still be running and can be ended later.
This API MUST be non-blocking.
130 131 132 |
# File 'lib/opentelemetry/trace/span.rb', line 130 def finish(end_timestamp: nil) self end |
#name=(new_name) ⇒ void
This method returns an undefined value.
Updates the Span name
Upon this update, any sampling behavior based on Span name will depend on the implementation.
114 |
# File 'lib/opentelemetry/trace/span.rb', line 114 def name=(new_name); end |
#recording? ⇒ Boolean
Return whether this span is recording.
41 42 43 |
# File 'lib/opentelemetry/trace/span.rb', line 41 def recording? false end |
#set_attribute(key, value) ⇒ self Also known as: []=
Set attribute
Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings.
56 57 58 |
# File 'lib/opentelemetry/trace/span.rb', line 56 def set_attribute(key, value) self end |
#status=(status) ⇒ void
This method returns an undefined value.
Sets the Status to the Span
If used, this will override the default Span status. Default is OK.
Only the value of the last call will be recorded, and implementations are free to ignore previous calls.
103 |
# File 'lib/opentelemetry/trace/span.rb', line 103 def status=(status); end |