[go: up one dir, main page]

Span

Trait Span 

Source
pub trait Span:
    AsAny
    + Send
    + Sync {
    // Required methods
    fn is_recording(&self) -> bool;
    fn span_id(&self) -> [u8; 8];
    fn end(&self);
    fn set_status(&self, status: SpanStatus);
    fn set_attribute(&self, key: &'static str, value: AttributeValue);
    fn record_error(&self, error: &dyn Error);
    fn set_current(&self, context: &Context<'_>) -> Box<dyn SpanGuard>;
    fn propagate_headers(&self, request: &mut Request);
}
Expand description

A trait that represents a span in distributed tracing.

This trait defines the methods that a span must implement to be used in distributed tracing. It includes methods for setting attributes, recording errors, and managing the span’s lifecycle.

Required Methods§

Source

fn is_recording(&self) -> bool

Returns true if an application is listening for events on the span.

Source

fn span_id(&self) -> [u8; 8]

The 8 byte value which identifies the span.

Source

fn end(&self)

Ends the current span.

Source

fn set_status(&self, status: SpanStatus)

Sets the status of the current span.

§Arguments
  • status: The status to set for the current span.
§Returns

A Result indicating success or failure of the operation.

Source

fn set_attribute(&self, key: &'static str, value: AttributeValue)

Sets an attribute on the current span.

§Arguments
  • key: The key of the attribute to set.
  • value: The value of the attribute to set.
Source

fn record_error(&self, error: &dyn Error)

Records a Rust standard error on the current span.

§Arguments
  • error: A reference to the error to be recorded.
§Returns

A Result indicating success or failure of the operation.

Source

fn set_current(&self, context: &Context<'_>) -> Box<dyn SpanGuard>

Temporarily sets the span as the current active span in the context.

§Arguments
  • context: The context in which to set the current span.
§Returns

A SpanGuard that will end the span when dropped.

This method allows the span to be set as the current span in the context, enabling it to be used for tracing operations within that context.

Source

fn propagate_headers(&self, request: &mut Request)

Adds telemetry headers to the request for distributed tracing.

§Arguments
  • request: A mutable reference to the request to which headers will be added.

This method should be called before sending the request to ensure that the tracing information is included in the request headers. It typically adds the W3C Distributed Tracing headers to the request.

Implementors§