Skip to main content

auditaur_core/model/
mod.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5#[serde(rename_all = "camelCase")]
6pub struct Session {
7    pub id: String,
8    pub session_name: Option<String>,
9    pub service_name: String,
10    pub service_version: Option<String>,
11    pub app_identifier: Option<String>,
12    pub pid: Option<i64>,
13    pub started_at: String,
14    pub ended_at: Option<String>,
15    pub schema_version: i64,
16    pub auditaur_version: Option<String>,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
20#[serde(rename_all = "camelCase")]
21pub struct LogRecord {
22    pub session_id: String,
23    pub timestamp_unix_nanos: i64,
24    pub observed_timestamp_unix_nanos: Option<i64>,
25    pub severity_text: Option<String>,
26    pub severity_number: Option<i64>,
27    pub body: Option<String>,
28    pub body_json: Option<Value>,
29    pub trace_id: Option<String>,
30    pub span_id: Option<String>,
31    pub scope_name: Option<String>,
32    pub scope_version: Option<String>,
33    pub attributes: Value,
34    pub source: TelemetrySource,
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
38#[serde(rename_all = "camelCase")]
39pub struct SpanRecord {
40    pub session_id: String,
41    pub trace_id: String,
42    pub span_id: String,
43    pub parent_span_id: Option<String>,
44    pub name: String,
45    pub kind: Option<String>,
46    pub start_time_unix_nanos: i64,
47    pub end_time_unix_nanos: Option<i64>,
48    pub status_code: Option<String>,
49    pub status_message: Option<String>,
50    pub scope_name: Option<String>,
51    pub scope_version: Option<String>,
52    pub attributes: Value,
53    pub source: TelemetrySource,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
57#[serde(rename_all = "camelCase")]
58pub struct SpanEventRecord {
59    pub session_id: String,
60    pub trace_id: String,
61    pub span_id: String,
62    pub name: String,
63    pub timestamp_unix_nanos: i64,
64    pub attributes: Value,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
68#[serde(rename_all = "camelCase")]
69pub struct FrontendError {
70    pub session_id: String,
71    pub timestamp_unix_nanos: i64,
72    pub message: String,
73    pub stack: Option<String>,
74    pub filename: Option<String>,
75    pub line_number: Option<i64>,
76    pub column_number: Option<i64>,
77    pub error_type: Option<String>,
78    pub trace_id: Option<String>,
79    pub span_id: Option<String>,
80    pub window_label: Option<String>,
81    pub attributes: Value,
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
85#[serde(rename_all = "camelCase")]
86pub struct TauriIpcCall {
87    pub session_id: String,
88    pub timestamp_unix_nanos: i64,
89    pub duration_ms: Option<f64>,
90    pub command: String,
91    pub status: String,
92    pub error_message: Option<String>,
93    pub trace_id: Option<String>,
94    pub span_id: Option<String>,
95    pub window_label: Option<String>,
96    pub args_json: Option<Value>,
97    pub args_redacted: bool,
98    pub result_summary: Option<String>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
102#[serde(rename_all = "camelCase")]
103pub struct TauriEventRecord {
104    pub session_id: String,
105    pub timestamp_unix_nanos: i64,
106    pub event_name: String,
107    pub direction: String,
108    pub target: Option<String>,
109    pub trace_id: Option<String>,
110    pub span_id: Option<String>,
111    pub window_label: Option<String>,
112    pub payload_summary: Option<String>,
113    pub payload_json: Option<Value>,
114    pub payload_redacted: bool,
115}
116
117#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
118#[serde(rename_all = "camelCase")]
119pub struct TauriWindowState {
120    pub session_id: String,
121    pub timestamp_unix_nanos: i64,
122    pub window_label: String,
123    pub webview_label: Option<String>,
124    pub url: Option<String>,
125    pub title: Option<String>,
126    pub focused: Option<bool>,
127    pub visible: Option<bool>,
128    pub width: Option<f64>,
129    pub height: Option<f64>,
130    pub scale_factor: Option<f64>,
131    pub attributes: Value,
132}
133
134#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
135#[serde(rename_all = "snake_case")]
136pub enum TelemetrySource {
137    Frontend,
138    Backend,
139    Plugin,
140    ThirdPartyOtel,
141}
142
143impl TelemetrySource {
144    pub fn as_str(self) -> &'static str {
145        match self {
146            Self::Frontend => "frontend",
147            Self::Backend => "backend",
148            Self::Plugin => "plugin",
149            Self::ThirdPartyOtel => "third_party_otel",
150        }
151    }
152
153    pub fn from_storage(value: &str) -> Self {
154        match value {
155            "frontend" => Self::Frontend,
156            "backend" => Self::Backend,
157            "plugin" => Self::Plugin,
158            "third_party_otel" => Self::ThirdPartyOtel,
159            _ => Self::ThirdPartyOtel,
160        }
161    }
162}