Skip to main content

systemprompt_runtime/trace/models/
trace.rs

1//! Trace-listing filters, events, and per-domain summaries.
2//!
3//! Copyright (c) systemprompt.io — Business Source License 1.1.
4//! See <https://systemprompt.io> for licensing details.
5
6use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8use systemprompt_identifiers::{
9    AgentName, ContextId, ExecutionStepId, SessionId, TaskId, TraceId, UserId,
10};
11
12#[derive(Debug, Clone)]
13pub struct TraceListFilter {
14    pub limit: i64,
15    pub since: Option<DateTime<Utc>>,
16    pub agent: Option<String>,
17    pub status: Option<String>,
18    pub tool: Option<String>,
19    pub has_mcp: bool,
20    pub include_system: bool,
21}
22
23impl TraceListFilter {
24    pub const fn new(limit: i64) -> Self {
25        Self {
26            limit,
27            since: None,
28            agent: None,
29            status: None,
30            tool: None,
31            has_mcp: false,
32            include_system: false,
33        }
34    }
35
36    pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
37        self.since = Some(since);
38        self
39    }
40
41    systemprompt_models::builder_methods! {
42        with_agent(agent) -> String,
43        with_status(status) -> String,
44        with_tool(tool) -> String,
45    }
46
47    pub const fn with_has_mcp(mut self, has_mcp: bool) -> Self {
48        self.has_mcp = has_mcp;
49        self
50    }
51
52    pub const fn with_include_system(mut self, include_system: bool) -> Self {
53        self.include_system = include_system;
54        self
55    }
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct TraceListItem {
60    pub trace_id: TraceId,
61    pub first_timestamp: DateTime<Utc>,
62    pub last_timestamp: DateTime<Utc>,
63    pub agent: Option<String>,
64    pub status: String,
65    pub ai_requests: i64,
66    pub mcp_calls: i64,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
70pub struct TraceEvent {
71    pub event_type: String,
72    pub timestamp: DateTime<Utc>,
73    pub details: String,
74    pub user_id: Option<UserId>,
75    pub session_id: Option<SessionId>,
76    pub task_id: Option<TaskId>,
77    pub context_id: Option<ContextId>,
78    pub metadata: Option<String>,
79}
80
81#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
82pub struct AiRequestSummary {
83    pub total_cost_microdollars: i64,
84    pub total_tokens: i64,
85    pub total_input_tokens: i64,
86    pub total_output_tokens: i64,
87    pub request_count: i64,
88    pub total_latency_ms: i64,
89}
90
91#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
92pub struct McpExecutionSummary {
93    pub execution_count: i64,
94    pub total_execution_time_ms: i64,
95}
96
97#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize)]
98pub struct ExecutionStepSummary {
99    #[serde(rename = "step_count")]
100    pub total: i64,
101    #[serde(rename = "completed_count")]
102    pub completed: i64,
103    #[serde(rename = "failed_count")]
104    pub failed: i64,
105    #[serde(rename = "pending_count")]
106    pub pending: i64,
107}
108
109#[derive(Debug, Clone, Serialize, Deserialize)]
110pub struct TaskInfo {
111    pub task_id: TaskId,
112    pub context_id: ContextId,
113    pub agent_name: Option<AgentName>,
114    pub status: String,
115    pub created_at: DateTime<Utc>,
116    pub started_at: Option<DateTime<Utc>>,
117    pub completed_at: Option<DateTime<Utc>>,
118    pub execution_time_ms: Option<i32>,
119    pub error_message: Option<String>,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct ExecutionStep {
124    pub step_id: ExecutionStepId,
125    pub step_type: Option<String>,
126    pub title: Option<String>,
127    pub status: String,
128    pub duration_ms: Option<i32>,
129    pub error_message: Option<String>,
130}