pub struct Span {
pub trace_id: String,
pub span_id: String,
pub parent_span_id: Option<String>,
pub name: String,
pub kind: SpanKind,
pub start_time: i64,
pub end_time: i64,
pub attributes: HashMap<String, String>,
pub events: Vec<SpanEvent>,
pub status: SpanStatus,
pub resource: Option<Resource>,
}Expand description
Represents a span within a trace
Fields§
§trace_id: StringTrace ID this span belongs to
span_id: StringSpan ID (unique within the trace)
parent_span_id: Option<String>Parent span ID (if this is a child span)
name: StringSpan name
kind: SpanKindSpan kind
start_time: i64Start time in nanoseconds since Unix epoch
end_time: i64End time in nanoseconds since Unix epoch
attributes: HashMap<String, String>Span attributes
events: Vec<SpanEvent>Span events
status: SpanStatusSpan status
resource: Option<Resource>Associated resource
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(
trace_id: impl Into<String>,
span_id: impl Into<String>,
name: impl Into<String>,
start_time: i64,
end_time: i64,
) -> Self
pub fn new( trace_id: impl Into<String>, span_id: impl Into<String>, name: impl Into<String>, start_time: i64, end_time: i64, ) -> Self
Create a new span
Sourcepub fn with_parent(self, parent_span_id: impl Into<String>) -> Self
pub fn with_parent(self, parent_span_id: impl Into<String>) -> Self
Set the parent span ID
Sourcepub fn with_attribute(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn with_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Add an attribute to the span
Sourcepub fn with_event(self, event: SpanEvent) -> Self
pub fn with_event(self, event: SpanEvent) -> Self
Add an event to the span
Sourcepub fn with_status(self, code: StatusCode, message: Option<String>) -> Self
pub fn with_status(self, code: StatusCode, message: Option<String>) -> Self
Set the span status
Sourcepub fn duration_ns(&self) -> i64
pub fn duration_ns(&self) -> i64
Calculate span duration in nanoseconds
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Span
impl<'de> Deserialize<'de> for Span
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Span
Auto Trait Implementations§
impl Freeze for Span
impl RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl UnsafeUnpin for Span
impl UnwindSafe for Span
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more