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