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