Struct opentelemetry_api::trace::SpanRef
source · pub struct SpanRef<'a>(/* private fields */);
Expand description
A reference to the currently active span in this context.
Implementations§
source§impl SpanRef<'_>
impl SpanRef<'_>
sourcepub fn add_event<T>(&self, name: T, attributes: Vec<KeyValue>)where
T: Into<Cow<'static, str>>,
pub fn add_event<T>(&self, name: T, attributes: Vec<KeyValue>)where T: Into<Cow<'static, str>>,
Record an event in the context this span.
Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings and are available via the opentelemetry_semantic_conventions crate.
sourcepub fn record_error(&self, err: &dyn Error)
pub fn record_error(&self, err: &dyn Error)
Record an error as an event for this span.
An additional call to Span::set_status is required if the status of the span should be set to error, as this method does not change the span status.
If this span is not being recorded then this method does nothing.
sourcepub fn add_event_with_timestamp<T>(
&self,
name: T,
timestamp: SystemTime,
attributes: Vec<KeyValue>
)where
T: Into<Cow<'static, str>>,
pub fn add_event_with_timestamp<T>( &self, name: T, timestamp: SystemTime, attributes: Vec<KeyValue> )where T: Into<Cow<'static, str>>,
Record an event with a timestamp in the context this span.
Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings and are available via the opentelemetry_semantic_conventions crate.
sourcepub fn span_context(&self) -> &SpanContext
pub fn span_context(&self) -> &SpanContext
A reference to the SpanContext
for this span.
sourcepub fn is_recording(&self) -> bool
pub fn is_recording(&self) -> bool
Returns true
if this span is recording information.
Spans will not be recording information after they have ended.
This flag may be true
despite the entire trace being sampled out. This
allows recording and processing of information about the individual
spans without sending it to the backend. An example of this scenario may
be recording and processing of all incoming requests for the processing
and building of SLA/SLO latency charts while sending only a subset -
sampled spans - to the backend.
sourcepub fn set_attribute(&self, attribute: KeyValue)
pub fn set_attribute(&self, attribute: KeyValue)
Set an attribute of this span.
Setting an attribute with the same key as an existing attribute generally overwrites the existing attribute’s value.
Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings and are available via the opentelemetry_semantic_conventions crate.
sourcepub fn set_attributes(&self, attributes: impl IntoIterator<Item = KeyValue>)
pub fn set_attributes(&self, attributes: impl IntoIterator<Item = KeyValue>)
Set multiple attributes of this span.
Setting an attribute with the same key as an existing attribute generally overwrites the existing attribute’s value.
Note that the OpenTelemetry project documents certain “standard attributes” that have prescribed semantic meanings and are available via the opentelemetry_semantic_conventions crate.
sourcepub fn set_status(&self, status: Status)
pub fn set_status(&self, status: Status)
Sets the status of this Span
.
If used, this will override the default span status, which is Status::Unset
.
sourcepub fn update_name<T>(&self, new_name: T)where
T: Into<Cow<'static, str>>,
pub fn update_name<T>(&self, new_name: T)where T: Into<Cow<'static, str>>,
Updates the span’s name.
After this update, any sampling behavior based on the name will depend on the implementation.
sourcepub fn end_with_timestamp(&self, timestamp: SystemTime)
pub fn end_with_timestamp(&self, timestamp: SystemTime)
Signals that the operation described by this span ended at the given time.