Trace Context • Rust AI Agent SDK

TraceContext: Context for a trace.

TraceContext

Defined in the trace module.

Rust AI Agent SDK

Context for a trace.

Fields

NameTypeDescription
idStringTrace ID
nameStringTrace name
start_timeInstantStart time
spans`Vec

| All spans | | span_stack | Vec<String> | Current span stack | | attributes | HashMap<String | Attributes | | serde_json | :Value>` | Attributes |

Methods

new

rust
fn new(name: impl Into<String>) -> Self

Create a new trace context.

Parameters:

NameType
nameimpl Into&lt;String&gt;

elapsed

rust
fn elapsed(&self) -> Duration

Get elapsed time since trace start.

start_span

rust
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

rust
fn end_span(&mut self, span_id: &str) -> ()

End a span.

Parameters:

NameType
span_id&str

current_span_id

rust
fn current_span_id(&self) -> Option<&str>

Get current span ID.

get_span

rust
fn get_span(&self, span_id: &str) -> Option<&Span>

Get a span by ID.

Parameters:

NameType
span_id&str

get_span_mut

rust
fn get_span_mut(&mut self, span_id: &str) -> Option<&mut Span>

Get mutable span by ID.

Parameters:

NameType
span_id&str

add_event

rust
fn add_event(&mut self, name: impl Into<String>) -> ()

Add event to current span.

Parameters:

NameType
nameimpl Into&lt;String&gt;

set_attribute

rust
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

rust
fn spans(&self) -> &[Span]

Get all spans.

span_count

rust
fn span_count(&self) -> usize

Get span count.

Source

View on GitHub

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


Related Documentation