Skip to main content

Span

Defined in the trace module.
Rust AI Agent SDK A span representing a unit of work.

Fields

NameTypeDescription
idStringSpan ID
parent_idOption<String>Parent span ID
trace_idStringTrace ID
nameStringSpan name
kindSpanKindSpan kind
statusSpanStatusSpan status
start_offsetDurationStart time (as duration since trace start)
end_offsetOption<Duration>End time (as duration since trace start)
durationOption<Duration>Duration
attributesHashMap<StringAttributes
serde_json:Value>Attributes
eventsVec<SpanEvent>Events
error_messageOption<String>Error message (if status is Error)

Methods

new

fn new(
        trace_id: impl Into<String>,
        name: impl Into<String>,
        kind: SpanKind,
        start_offset: Duration,
    ) -> Self
Create a new span. Parameters:
NameType
trace_idimpl Into&lt;String&gt;
nameimpl Into&lt;String&gt;
kindSpanKind
start_offsetDuration

with_parent

fn with_parent(mut self, parent_id: impl Into<String>) -> Self
Set parent span. Parameters:
NameType
parent_idimpl Into&lt;String&gt;

set_attribute

fn set_attribute(&mut self, key: impl Into<String>, value: impl Serialize) -> ()
Add an attribute. Parameters:
NameType
keyimpl Into&lt;String&gt;
valueimpl Serialize

add_event

fn add_event(&mut self, event: SpanEvent) -> ()
Add an event. Parameters:
NameType
eventSpanEvent

end

fn end(&mut self, end_offset: Duration) -> ()
End the span. Parameters:
NameType
end_offsetDuration

set_error

fn set_error(&mut self, message: impl Into<String>) -> ()
Mark as error. Parameters:
NameType
messageimpl Into&lt;String&gt;

is_ended

fn is_ended(&self) -> bool
Check if span is ended.

Source

View on GitHub

praisonai/src/trace/mod.rs at line 81