Struct opentelemetry::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<'_>

source

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.

source

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.

source

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.

source

pub fn span_context(&self) -> &SpanContext

A reference to the SpanContext for this span.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn end(&self)

Signals that the operation described by this span has now ended.

source

pub fn end_with_timestamp(&self, timestamp: SystemTime)

Signals that the operation described by this span ended at the given time.

Trait Implementations§

source§

impl<'a> Debug for SpanRef<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SpanRef<'a>

§

impl<'a> RefUnwindSafe for SpanRef<'a>

§

impl<'a> Send for SpanRef<'a>

§

impl<'a> Sync for SpanRef<'a>

§

impl<'a> Unpin for SpanRef<'a>

§

impl<'a> UnwindSafe for SpanRef<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.