Skip to main content

TraceSpan

Struct TraceSpan 

Source
pub struct TraceSpan {
Show 24 fields pub trace_id: Uuid, pub span_id: Uuid, pub parent_span_id: Option<Uuid>, pub tenant_id: TenantId, pub operation_name: String, pub start_time: DateTime<Utc>, pub end_time: Option<DateTime<Utc>>, pub provider: LLMProvider, pub model_name: String, pub prompt: String, pub response: Option<String>, pub prompt_tokens: Option<u32>, pub completion_tokens: Option<u32>, pub total_tokens: Option<u32>, pub time_to_first_token_ms: Option<u64>, pub duration_ms: Option<u64>, pub status_code: Option<u16>, pub error_message: Option<String>, pub estimated_cost_usd: Option<f64>, pub security_score: Option<u8>, pub security_findings: Vec<SecurityFinding>, pub tags: HashMap<String, String>, pub events: Vec<SpanEvent>, pub agent_actions: Vec<AgentAction>,
}
Expand description

A single span within a trace representing a portion of an LLM interaction.

Fields§

§trace_id: Uuid

Unique identifier for the trace this span belongs to.

§span_id: Uuid

Unique identifier for this span.

§parent_span_id: Option<Uuid>

Parent span ID if this is a child span.

§tenant_id: TenantId

Tenant this span belongs to.

§operation_name: String

Name of the operation (e.g., “chat_completion”, “embedding”, “prompt_analysis”).

§start_time: DateTime<Utc>

When the span started.

§end_time: Option<DateTime<Utc>>

When the span ended (None if still in progress).

§provider: LLMProvider

LLM provider used for this span.

§model_name: String

Model name/identifier.

§prompt: String

The input prompt or messages.

§response: Option<String>

The response from the LLM (None if not yet completed).

§prompt_tokens: Option<u32>

Number of tokens in the prompt.

§completion_tokens: Option<u32>

Number of tokens in the completion/response.

§total_tokens: Option<u32>

Total token count (prompt + completion).

§time_to_first_token_ms: Option<u64>

Time to first token (TTFT) in milliseconds.

§duration_ms: Option<u64>

Processing duration in milliseconds.

§status_code: Option<u16>

HTTP status code of the response.

§error_message: Option<String>

Error message if the request failed.

§estimated_cost_usd: Option<f64>

Estimated cost of this request in USD.

§security_score: Option<u8>

Overall security score (0-100, higher = more suspicious).

§security_findings: Vec<SecurityFinding>

Security findings detected for this span.

§tags: HashMap<String, String>

Custom tags and metadata.

§events: Vec<SpanEvent>

Events that occurred during this span (e.g., streaming chunks, analysis results).

§agent_actions: Vec<AgentAction>

Agent actions captured during this span (tool calls, commands, web access, etc.).

Implementations§

Source§

impl TraceSpan

Source

pub fn new( trace_id: Uuid, tenant_id: TenantId, operation_name: String, provider: LLMProvider, model_name: String, prompt: String, ) -> Self

Create a new trace span.

Source

pub fn finish_with_response(self, response: String) -> Self

Finish the span with a response.

Source

pub fn finish_with_error(self, error: String, status_code: Option<u16>) -> Self

Mark the span as failed with an error.

Source

pub fn add_security_finding(&mut self, finding: SecurityFinding)

Add a security finding to this span.

Source

pub fn add_event(&mut self, event: SpanEvent)

Add an event to this span.

Source

pub fn add_agent_action(&mut self, action: AgentAction)

Add an agent action to this span.

Source

pub fn tool_calls(&self) -> Vec<&AgentAction>

Return all tool call actions in this span.

Source

pub fn web_accesses(&self) -> Vec<&AgentAction>

Return all web access actions in this span.

Source

pub fn commands(&self) -> Vec<&AgentAction>

Return all command execution actions in this span.

Source

pub fn has_tool_calls(&self) -> bool

Check if this span has any tool call actions.

Source

pub fn has_web_access(&self) -> bool

Check if this span has any web access actions.

Source

pub fn has_commands(&self) -> bool

Check if this span has any command execution actions.

Source

pub fn duration(&self) -> Option<Duration>

Get the duration of this span.

Source

pub fn is_complete(&self) -> bool

Check if the span is complete.

Source

pub fn is_failed(&self) -> bool

Check if the span failed.

Trait Implementations§

Source§

impl Clone for TraceSpan

Source§

fn clone(&self) -> TraceSpan

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComposeSchema for TraceSpan

Source§

impl Debug for TraceSpan

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TraceSpan

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TraceSpan

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToSchema for TraceSpan

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,