telemetry_events.rs

  1use semantic_version::SemanticVersion;
  2use serde::{Deserialize, Serialize};
  3use std::{fmt::Display, sync::Arc, time::Duration};
  4
  5#[derive(Serialize, Deserialize, Debug)]
  6pub struct EventRequestBody {
  7    pub installation_id: Option<String>,
  8    pub session_id: Option<String>,
  9    pub is_staff: Option<bool>,
 10    pub app_version: String,
 11    pub os_name: String,
 12    pub os_version: Option<String>,
 13    pub architecture: String,
 14    pub release_channel: Option<String>,
 15    pub events: Vec<EventWrapper>,
 16}
 17
 18impl EventRequestBody {
 19    pub fn semver(&self) -> Option<SemanticVersion> {
 20        self.app_version.parse().ok()
 21    }
 22}
 23
 24#[derive(Serialize, Deserialize, Debug)]
 25pub struct EventWrapper {
 26    pub signed_in: bool,
 27    pub milliseconds_since_first_event: i64,
 28    #[serde(flatten)]
 29    pub event: Event,
 30}
 31
 32#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 33#[serde(rename_all = "snake_case")]
 34pub enum AssistantKind {
 35    Panel,
 36    Inline,
 37}
 38
 39impl Display for AssistantKind {
 40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 41        write!(
 42            f,
 43            "{}",
 44            match self {
 45                Self::Panel => "panel",
 46                Self::Inline => "inline",
 47            }
 48        )
 49    }
 50}
 51
 52#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 53#[serde(tag = "type")]
 54pub enum Event {
 55    Editor(EditorEvent),
 56    Copilot(CopilotEvent), // Needed for clients sending old copilot_event types
 57    InlineCompletion(InlineCompletionEvent),
 58    Call(CallEvent),
 59    Assistant(AssistantEvent),
 60    Cpu(CpuEvent),
 61    Memory(MemoryEvent),
 62    App(AppEvent),
 63    Setting(SettingEvent),
 64    Extension(ExtensionEvent),
 65    Edit(EditEvent),
 66    Action(ActionEvent),
 67}
 68
 69#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 70pub struct EditorEvent {
 71    pub operation: String,
 72    pub file_extension: Option<String>,
 73    pub vim_mode: bool,
 74    pub copilot_enabled: bool,
 75    pub copilot_enabled_for_language: bool,
 76}
 77
 78// Needed for clients sending old copilot_event types
 79#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 80pub struct CopilotEvent {
 81    pub suggestion_id: Option<String>,
 82    pub suggestion_accepted: bool,
 83    pub file_extension: Option<String>,
 84}
 85
 86#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 87pub struct InlineCompletionEvent {
 88    pub provider: String,
 89    pub suggestion_accepted: bool,
 90    pub file_extension: Option<String>,
 91}
 92
 93#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 94pub struct CallEvent {
 95    pub operation: String,
 96    pub room_id: Option<u64>,
 97    pub channel_id: Option<u64>,
 98}
 99
100#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
101pub struct AssistantEvent {
102    pub conversation_id: Option<String>,
103    pub kind: AssistantKind,
104    pub model: String,
105    pub response_latency: Option<Duration>,
106    pub error_message: Option<String>,
107}
108
109#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
110pub struct CpuEvent {
111    pub usage_as_percentage: f32,
112    pub core_count: u32,
113}
114
115#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
116pub struct MemoryEvent {
117    pub memory_in_bytes: u64,
118    pub virtual_memory_in_bytes: u64,
119}
120
121#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
122pub struct ActionEvent {
123    pub source: String,
124    pub action: String,
125}
126
127#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
128pub struct EditEvent {
129    pub duration: i64,
130    pub environment: String,
131}
132
133#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
134pub struct SettingEvent {
135    pub setting: String,
136    pub value: String,
137}
138
139#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
140pub struct ExtensionEvent {
141    pub extension_id: Arc<str>,
142    pub version: Arc<str>,
143}
144
145#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
146pub struct AppEvent {
147    pub operation: String,
148}
149
150#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
151pub struct BacktraceFrame {
152    pub ip: usize,
153    pub symbol_addr: usize,
154    pub base: Option<usize>,
155    pub symbols: Vec<String>,
156}
157
158#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
159pub struct HangReport {
160    pub backtrace: Vec<BacktraceFrame>,
161    pub app_version: Option<SemanticVersion>,
162    pub os_name: String,
163    pub os_version: Option<SemanticVersion>,
164    pub architecture: String,
165    pub installation_id: Option<String>,
166}
167
168#[derive(Serialize, Deserialize)]
169pub struct LocationData {
170    pub file: String,
171    pub line: u32,
172}
173
174#[derive(Serialize, Deserialize)]
175pub struct Panic {
176    pub thread: String,
177    pub payload: String,
178    #[serde(skip_serializing_if = "Option::is_none")]
179    pub location_data: Option<LocationData>,
180    pub backtrace: Vec<String>,
181    pub app_version: String,
182    pub release_channel: String,
183    pub os_name: String,
184    pub os_version: Option<String>,
185    pub architecture: String,
186    pub panicked_on: i64,
187    #[serde(skip_serializing_if = "Option::is_none")]
188    pub installation_id: Option<String>,
189    pub session_id: String,
190}
191
192#[derive(Serialize, Deserialize)]
193pub struct PanicRequest {
194    pub panic: Panic,
195}