telemetry_events.rs

  1//! See [Telemetry in Zed](https://zed.dev/docs/telemetry) for additional information.
  2
  3use semantic_version::SemanticVersion;
  4use serde::{Deserialize, Serialize};
  5use std::{fmt::Display, sync::Arc, time::Duration};
  6
  7#[derive(Serialize, Deserialize, Debug)]
  8pub struct EventRequestBody {
  9    /// Identifier unique to each system Zed is installed on
 10    pub system_id: Option<String>,
 11    /// Identifier unique to each Zed installation (differs for stable, preview, dev)
 12    pub installation_id: Option<String>,
 13    /// Identifier unique to each logged in Zed user (randomly generated on first sign in)
 14    /// Identifier unique to each Zed session (differs for each time you open Zed)
 15    pub session_id: Option<String>,
 16    pub metrics_id: Option<String>,
 17    /// True for Zed staff, otherwise false
 18    pub is_staff: Option<bool>,
 19    /// Zed version number
 20    pub app_version: String,
 21    pub os_name: String,
 22    pub os_version: Option<String>,
 23    pub architecture: String,
 24    /// Zed release channel (stable, preview, dev)
 25    pub release_channel: Option<String>,
 26    pub events: Vec<EventWrapper>,
 27}
 28
 29impl EventRequestBody {
 30    pub fn semver(&self) -> Option<SemanticVersion> {
 31        self.app_version.parse().ok()
 32    }
 33}
 34
 35#[derive(Serialize, Deserialize, Debug)]
 36pub struct EventWrapper {
 37    pub signed_in: bool,
 38    /// Duration between this event's timestamp and the timestamp of the first event in the current batch
 39    pub milliseconds_since_first_event: i64,
 40    /// The event itself
 41    #[serde(flatten)]
 42    pub event: Event,
 43}
 44
 45#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 46#[serde(rename_all = "snake_case")]
 47pub enum AssistantKind {
 48    Panel,
 49    Inline,
 50}
 51impl Display for AssistantKind {
 52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 53        write!(
 54            f,
 55            "{}",
 56            match self {
 57                Self::Panel => "panel",
 58                Self::Inline => "inline",
 59            }
 60        )
 61    }
 62}
 63
 64#[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)]
 65#[serde(rename_all = "snake_case")]
 66pub enum AssistantPhase {
 67    #[default]
 68    Response,
 69    Invoked,
 70    Accepted,
 71    Rejected,
 72}
 73
 74impl Display for AssistantPhase {
 75    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
 76        write!(
 77            f,
 78            "{}",
 79            match self {
 80                Self::Response => "response",
 81                Self::Invoked => "invoked",
 82                Self::Accepted => "accepted",
 83                Self::Rejected => "rejected",
 84            }
 85        )
 86    }
 87}
 88
 89#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
 90#[serde(tag = "type")]
 91pub enum Event {
 92    Editor(EditorEvent),
 93    InlineCompletion(InlineCompletionEvent),
 94    Call(CallEvent),
 95    Assistant(AssistantEvent),
 96    Cpu(CpuEvent),
 97    Memory(MemoryEvent),
 98    App(AppEvent),
 99    Setting(SettingEvent),
100    Extension(ExtensionEvent),
101    Edit(EditEvent),
102    Action(ActionEvent),
103    Repl(ReplEvent),
104}
105
106#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
107pub struct EditorEvent {
108    /// The editor operation performed (open, save)
109    pub operation: String,
110    /// The extension of the file that was opened or saved
111    pub file_extension: Option<String>,
112    /// Whether the user is in vim mode or not
113    pub vim_mode: bool,
114    /// Whether the user has copilot enabled or not
115    pub copilot_enabled: bool,
116    /// Whether the user has copilot enabled for the language of the file opened or saved
117    pub copilot_enabled_for_language: bool,
118    /// Whether the client is opening/saving a local file or a remote file via SSH
119    #[serde(default)]
120    pub is_via_ssh: bool,
121}
122
123#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
124pub struct InlineCompletionEvent {
125    /// Provider of the completion suggestion (e.g. copilot, supermaven)
126    pub provider: String,
127    pub suggestion_accepted: bool,
128    pub file_extension: Option<String>,
129}
130
131#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
132pub struct CallEvent {
133    /// Operation performed: invite/join call; begin/end screenshare; share/unshare project; etc
134    pub operation: String,
135    pub room_id: Option<u64>,
136    pub channel_id: Option<u64>,
137}
138
139#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
140pub struct AssistantEvent {
141    /// Unique random identifier for each assistant tab (None for inline assist)
142    pub conversation_id: Option<String>,
143    /// The kind of assistant (Panel, Inline)
144    pub kind: AssistantKind,
145    #[serde(default)]
146    pub phase: AssistantPhase,
147    /// Name of the AI model used (gpt-4o, claude-3-5-sonnet, etc)
148    pub model: String,
149    pub model_provider: String,
150    pub response_latency: Option<Duration>,
151    pub error_message: Option<String>,
152    pub language_name: Option<String>,
153}
154
155#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
156pub struct CpuEvent {
157    pub usage_as_percentage: f32,
158    pub core_count: u32,
159}
160
161#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
162pub struct MemoryEvent {
163    pub memory_in_bytes: u64,
164    pub virtual_memory_in_bytes: u64,
165}
166
167#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
168pub struct ActionEvent {
169    pub source: String,
170    pub action: String,
171}
172
173#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
174pub struct EditEvent {
175    pub duration: i64,
176    pub environment: String,
177    /// Whether the edits occurred locally or remotely via SSH
178    #[serde(default)]
179    pub is_via_ssh: bool,
180}
181
182#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
183pub struct SettingEvent {
184    pub setting: String,
185    pub value: String,
186}
187
188#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
189pub struct ExtensionEvent {
190    pub extension_id: Arc<str>,
191    pub version: Arc<str>,
192}
193
194#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
195pub struct AppEvent {
196    pub operation: String,
197}
198
199#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
200pub struct ReplEvent {
201    pub kernel_language: String,
202    pub kernel_status: String,
203    pub repl_session_id: String,
204}
205
206#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
207pub struct BacktraceFrame {
208    pub ip: usize,
209    pub symbol_addr: usize,
210    pub base: Option<usize>,
211    pub symbols: Vec<String>,
212}
213
214#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
215pub struct HangReport {
216    pub backtrace: Vec<BacktraceFrame>,
217    pub app_version: Option<SemanticVersion>,
218    pub os_name: String,
219    pub os_version: Option<String>,
220    pub architecture: String,
221    /// Identifier unique to each Zed installation (differs for stable, preview, dev)
222    pub installation_id: Option<String>,
223}
224
225#[derive(Serialize, Deserialize)]
226pub struct LocationData {
227    pub file: String,
228    pub line: u32,
229}
230
231#[derive(Serialize, Deserialize)]
232pub struct Panic {
233    /// The name of the thread that panicked
234    pub thread: String,
235    /// The panic message
236    pub payload: String,
237    /// The location of the panic (file, line number)
238    #[serde(skip_serializing_if = "Option::is_none")]
239    pub location_data: Option<LocationData>,
240    pub backtrace: Vec<String>,
241    /// Zed version number
242    pub app_version: String,
243    /// Zed release channel (stable, preview, dev)
244    pub release_channel: String,
245    pub os_name: String,
246    pub os_version: Option<String>,
247    pub architecture: String,
248    /// The time the panic occurred (UNIX millisecond timestamp)
249    pub panicked_on: i64,
250    /// Identifier unique to each system Zed is installed on
251    #[serde(skip_serializing_if = "Option::is_none")]
252    pub system_id: Option<String>,
253    /// Identifier unique to each Zed installation (differs for stable, preview, dev)
254    #[serde(skip_serializing_if = "Option::is_none")]
255    pub installation_id: Option<String>,
256    /// Identifier unique to each Zed session (differs for each time you open Zed)
257    pub session_id: String,
258}
259
260#[derive(Serialize, Deserialize)]
261pub struct PanicRequest {
262    pub panic: Panic,
263}