Skip to main content

TraceContext

Defined in the trace module.
Rust AI Agent SDK Context for a trace.

Fields

NameTypeDescription
idStringTrace ID
nameStringTrace name
start_timeInstantStart time
spansVec<Span>All spans
span_stackVec<String>Current span stack
attributesHashMap<StringAttributes
serde_json:Value>Attributes

Methods

new

fn new(name: impl Into<String>) -> Self
Create a new trace context. Parameters:
NameType
nameimpl Into&lt;String&gt;

elapsed

fn elapsed(&self) -> Duration
Get elapsed time since trace start.

start_span

fn start_span(&mut self, name: impl Into<String>, kind: SpanKind) -> String
Start a new span. Parameters:
NameType
nameimpl Into&lt;String&gt;
kindSpanKind

end_span

fn end_span(&mut self, span_id: &str) -> ()
End a span. Parameters:
NameType
span_id&str

current_span_id

fn current_span_id(&self) -> Option<&str>
Get current span ID.

get_span

fn get_span(&self, span_id: &str) -> Option<&Span>
Get a span by ID. Parameters:
NameType
span_id&str

get_span_mut

fn get_span_mut(&mut self, span_id: &str) -> Option<&mut Span>
Get mutable span by ID. Parameters:
NameType
span_id&str

add_event

fn add_event(&mut self, name: impl Into<String>) -> ()
Add event to current span. Parameters:
NameType
nameimpl Into&lt;String&gt;

set_attribute

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

spans

fn spans(&self) -> &[Span]
Get all spans.

span_count

fn span_count(&self) -> usize
Get span count.

Source

View on GitHub

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