pub struct Span {
pub span_id: SpanId,
pub parent_span_id: Option<SpanId>,
pub trace_id: TraceId,
pub name: String,
pub kind: SpanKind,
pub start_time_us: u64,
pub end_time_us: Option<u64>,
pub attributes: HashMap<String, AttributeValue>,
pub status: SpanStatus,
pub events: Vec<SpanEvent>,
pub links: Vec<SpanLink>,
pub node_id: NodeId,
}Expand description
A span represents a unit of work in a trace
Fields§
§span_id: SpanIdUnique span ID
parent_span_id: Option<SpanId>Parent span ID (None for root spans)
trace_id: TraceIdTrace this span belongs to
name: StringHuman-readable name
kind: SpanKindKind of span
start_time_us: u64Start timestamp (microseconds since Unix epoch)
end_time_us: Option<u64>End timestamp (microseconds since Unix epoch)
attributes: HashMap<String, AttributeValue>Span attributes
status: SpanStatusStatus
events: Vec<SpanEvent>Events that occurred during the span
links: Vec<SpanLink>Links to other spans
node_id: NodeIdNode that created this span
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(trace_id: TraceId, name: impl Into<String>, node_id: NodeId) -> Self
pub fn new(trace_id: TraceId, name: impl Into<String>, node_id: NodeId) -> Self
Create a new root span within the given trace
Sourcepub fn with_parent(self, parent: SpanId) -> Self
pub fn with_parent(self, parent: SpanId) -> Self
Set the parent span ID on this span
Sourcepub fn set_attribute(
&mut self,
key: impl Into<String>,
value: impl Into<AttributeValue>,
)
pub fn set_attribute( &mut self, key: impl Into<String>, value: impl Into<AttributeValue>, )
Insert a key-value attribute on this span
Sourcepub fn add_event(&mut self, name: impl Into<String>)
pub fn add_event(&mut self, name: impl Into<String>)
Record a named event on this span at the current time
Sourcepub fn add_event_with_attributes(
&mut self,
name: impl Into<String>,
attributes: HashMap<String, AttributeValue>,
)
pub fn add_event_with_attributes( &mut self, name: impl Into<String>, attributes: HashMap<String, AttributeValue>, )
Record a named event with additional attributes on this span
Sourcepub fn add_link(&mut self, trace_id: TraceId, span_id: SpanId)
pub fn add_link(&mut self, trace_id: TraceId, span_id: SpanId)
Add a causal link to another span in a different trace
Sourcepub fn set_error(&mut self, message: impl Into<String>)
pub fn set_error(&mut self, message: impl Into<String>)
Mark this span as failed with the given error message
Sourcepub fn duration_us(&self) -> Option<u64>
pub fn duration_us(&self) -> Option<u64>
Return the elapsed duration in microseconds, if the span has ended