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§
Sourcefn is_recording(&self) -> bool
fn is_recording(&self) -> bool
Returns true if an application is listening for events on the span.
Sourcefn set_status(&self, status: SpanStatus)
fn set_status(&self, status: SpanStatus)
Sourcefn set_attribute(&self, key: &'static str, value: AttributeValue)
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.
Sourcefn record_error(&self, error: &dyn Error)
fn record_error(&self, error: &dyn Error)
Sourcefn set_current(&self, context: &Context<'_>) -> Box<dyn SpanGuard>
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.
Sourcefn propagate_headers(&self, request: &mut Request)
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.