Skip to main content

systemprompt_logging/trace/models/
trace.rs

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