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::{collections::HashMap, fmt::Display, sync::Arc, time::Duration};
  6
  7#[derive(Serialize, Deserialize, Debug, Clone)]
  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, Clone)]
 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    Flexible(FlexibleEvent),
 95    Editor(EditorEvent),
 96    InlineCompletion(InlineCompletionEvent),
 97    InlineCompletionRating(InlineCompletionRatingEvent),
 98    Call(CallEvent),
 99    Assistant(AssistantEvent),
100    AssistantThreadFeedback(AssistantThreadFeedbackEvent),
101    Cpu(CpuEvent),
102    Memory(MemoryEvent),
103    App(AppEvent),
104    Setting(SettingEvent),
105    Extension(ExtensionEvent),
106    Edit(EditEvent),
107    Action(ActionEvent),
108    Repl(ReplEvent),
109}
110
111#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
112pub struct FlexibleEvent {
113    pub event_type: String,
114    pub event_properties: HashMap<String, serde_json::Value>,
115}
116
117#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
118pub struct EditorEvent {
119    /// The editor operation performed (open, save)
120    pub operation: String,
121    /// The extension of the file that was opened or saved
122    pub file_extension: Option<String>,
123    /// Whether the user is in vim mode or not
124    pub vim_mode: bool,
125    /// Whether the user has copilot enabled or not
126    pub copilot_enabled: bool,
127    /// Whether the user has copilot enabled for the language of the file opened or saved
128    pub copilot_enabled_for_language: bool,
129    /// Whether the client is opening/saving a local file or a remote file via SSH
130    #[serde(default)]
131    pub is_via_ssh: bool,
132}
133
134#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
135pub struct InlineCompletionEvent {
136    /// Provider of the completion suggestion (e.g. copilot, supermaven)
137    pub provider: String,
138    pub suggestion_accepted: bool,
139    pub file_extension: Option<String>,
140}
141
142#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
143pub enum InlineCompletionRating {
144    Positive,
145    Negative,
146}
147
148#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
149pub struct InlineCompletionRatingEvent {
150    pub rating: InlineCompletionRating,
151    pub input_events: Arc<str>,
152    pub input_excerpt: Arc<str>,
153    pub output_excerpt: Arc<str>,
154    pub feedback: String,
155}
156
157#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
158pub struct CallEvent {
159    /// Operation performed: invite/join call; begin/end screenshare; share/unshare project; etc
160    pub operation: String,
161    pub room_id: Option<u64>,
162    pub channel_id: Option<u64>,
163}
164
165#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
166pub struct AssistantEvent {
167    /// Unique random identifier for each assistant tab (None for inline assist)
168    pub conversation_id: Option<String>,
169    /// Server-generated message ID (only supported for some providers)
170    pub message_id: Option<String>,
171    /// The kind of assistant (Panel, Inline)
172    pub kind: AssistantKind,
173    #[serde(default)]
174    pub phase: AssistantPhase,
175    /// Name of the AI model used (gpt-4o, claude-3-5-sonnet, etc)
176    pub model: String,
177    pub model_provider: String,
178    pub response_latency: Option<Duration>,
179    pub error_message: Option<String>,
180    pub language_name: Option<String>,
181}
182
183#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
184pub struct CpuEvent {
185    pub usage_as_percentage: f32,
186    pub core_count: u32,
187}
188
189#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
190pub struct MemoryEvent {
191    pub memory_in_bytes: u64,
192    pub virtual_memory_in_bytes: u64,
193}
194
195#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
196pub struct ActionEvent {
197    pub source: String,
198    pub action: String,
199}
200
201#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
202pub struct EditEvent {
203    pub duration: i64,
204    pub environment: String,
205    /// Whether the edits occurred locally or remotely via SSH
206    #[serde(default)]
207    pub is_via_ssh: bool,
208}
209
210#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
211pub struct SettingEvent {
212    pub setting: String,
213    pub value: String,
214}
215
216#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
217pub struct ExtensionEvent {
218    pub extension_id: Arc<str>,
219    pub version: Arc<str>,
220}
221
222#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
223pub struct AppEvent {
224    pub operation: String,
225}
226
227#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
228pub struct ReplEvent {
229    pub kernel_language: String,
230    pub kernel_status: String,
231    pub repl_session_id: String,
232}
233
234#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
235pub enum ThreadFeedbackRating {
236    Positive,
237    Negative,
238}
239
240#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
241pub struct AssistantThreadFeedbackEvent {
242    /// Unique identifier for the thread
243    pub thread_id: String,
244    /// The feedback rating (thumbs up or thumbs down)
245    pub rating: ThreadFeedbackRating,
246    /// The serialized thread data containing messages, tool calls, etc.
247    pub thread_data: serde_json::Value,
248    /// The initial project snapshot taken when the thread was created
249    pub initial_project_snapshot: serde_json::Value,
250    /// The final project snapshot taken when the thread was first saved
251    pub final_project_snapshot: serde_json::Value,
252}
253
254#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
255pub struct BacktraceFrame {
256    pub ip: usize,
257    pub symbol_addr: usize,
258    pub base: Option<usize>,
259    pub symbols: Vec<String>,
260}
261
262#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
263pub struct HangReport {
264    pub backtrace: Vec<BacktraceFrame>,
265    pub app_version: Option<SemanticVersion>,
266    pub os_name: String,
267    pub os_version: Option<String>,
268    pub architecture: String,
269    /// Identifier unique to each Zed installation (differs for stable, preview, dev)
270    pub installation_id: Option<String>,
271}
272
273#[derive(Serialize, Deserialize, Clone, Debug)]
274pub struct LocationData {
275    pub file: String,
276    pub line: u32,
277}
278
279#[derive(Serialize, Deserialize, Clone, Debug)]
280pub struct Panic {
281    /// The name of the thread that panicked
282    pub thread: String,
283    /// The panic message
284    pub payload: String,
285    /// The location of the panic (file, line number)
286    #[serde(skip_serializing_if = "Option::is_none")]
287    pub location_data: Option<LocationData>,
288    pub backtrace: Vec<String>,
289    /// Zed version number
290    pub app_version: String,
291    /// The Git commit SHA that Zed was built at.
292    #[serde(skip_serializing_if = "Option::is_none")]
293    pub app_commit_sha: Option<String>,
294    /// Zed release channel (stable, preview, dev)
295    pub release_channel: String,
296    pub target: Option<String>,
297    pub os_name: String,
298    pub os_version: Option<String>,
299    pub architecture: String,
300    /// The time the panic occurred (UNIX millisecond timestamp)
301    pub panicked_on: i64,
302    /// Identifier unique to each system Zed is installed on
303    #[serde(skip_serializing_if = "Option::is_none")]
304    pub system_id: Option<String>,
305    /// Identifier unique to each Zed installation (differs for stable, preview, dev)
306    #[serde(skip_serializing_if = "Option::is_none")]
307    pub installation_id: Option<String>,
308    /// Identifier unique to each Zed session (differs for each time you open Zed)
309    pub session_id: String,
310}
311
312#[derive(Serialize, Deserialize)]
313pub struct PanicRequest {
314    pub panic: Panic,
315}