Span • Rust AI Agent SDK

Span: A span representing a unit of work.

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

rust
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

rust
fn with_parent(mut self, parent_id: impl Into<String>) -> Self

Set parent span.

Parameters:

NameType
parent_idimpl Into&lt;String&gt;

set_attribute

rust
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

rust
fn add_event(&mut self, event: SpanEvent) -> ()

Add an event.

Parameters:

NameType
eventSpanEvent

end

rust
fn end(&mut self, end_offset: Duration) -> ()

End the span.

Parameters:

NameType
end_offsetDuration

set_error

rust
fn set_error(&mut self, message: impl Into<String>) -> ()

Mark as error.

Parameters:

NameType
messageimpl Into&lt;String&gt;

is_ended

rust
fn is_ended(&self) -> bool

Check if span is ended.

Source

View on GitHub

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