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
| Name | Type | Description |
|---|---|---|
id | String | Span ID |
parent_id | Option<String> | Parent span ID |
trace_id | String | Trace ID |
name | String | Span name |
kind | SpanKind | Span kind |
status | SpanStatus | Span status |
start_offset | Duration | Start time (as duration since trace start) |
end_offset | Option<Duration> | End time (as duration since trace start) |
duration | Option<Duration> | Duration |
attributes | HashMap<String | Attributes |
serde_json | :Value> | Attributes |
events | Vec<SpanEvent> | Events |
error_message | Option<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,
) -> SelfCreate a new span.
Parameters:
| Name | Type |
|---|---|
trace_id | impl Into<String> |
name | impl Into<String> |
kind | SpanKind |
start_offset | Duration |
with_parent
fn with_parent(mut self, parent_id: impl Into<String>) -> SelfSet parent span.
Parameters:
| Name | Type |
|---|---|
parent_id | impl Into<String> |
set_attribute
fn set_attribute(&mut self, key: impl Into<String>, value: impl Serialize) -> ()Add an attribute.
Parameters:
| Name | Type |
|---|---|
key | impl Into<String> |
value | impl Serialize |
add_event
fn add_event(&mut self, event: SpanEvent) -> ()Add an event.
Parameters:
| Name | Type |
|---|---|
event | SpanEvent |
end
fn end(&mut self, end_offset: Duration) -> ()End the span.
Parameters:
| Name | Type |
|---|---|
end_offset | Duration |
set_error
fn set_error(&mut self, message: impl Into<String>) -> ()Mark as error.
Parameters:
| Name | Type |
|---|---|
message | impl Into<String> |
is_ended
fn is_ended(&self) -> boolCheck if span is ended.
Source
View on GitHubpraisonai/src/trace/mod.rs at line 81