From ba9a9f4f172d0ed803bf266f081c8867a35105ab Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 15 Jan 2024 16:26:04 -0500 Subject: [PATCH] Add more open events project search diagnostics welcome page --- crates/client/src/telemetry.rs | 48 ++++++++++++------- crates/collab_ui/src/channel_view.rs | 4 ++ crates/diagnostics/src/diagnostics.rs | 4 ++ crates/editor/src/items.rs | 4 ++ crates/language_tools/src/lsp_log.rs | 4 ++ crates/language_tools/src/syntax_tree_view.rs | 4 ++ crates/search/src/project_search.rs | 4 ++ crates/terminal_view/src/terminal_view.rs | 4 ++ crates/welcome/src/welcome.rs | 27 +++++++---- crates/workspace/src/item.rs | 11 +++++ crates/workspace/src/shared_screen.rs | 4 ++ crates/workspace/src/workspace.rs | 12 ++++- crates/zed/src/main.rs | 11 +++-- 13 files changed, 110 insertions(+), 31 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index ca717c9d6a..203840ac1b 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -116,7 +116,7 @@ pub enum Event { milliseconds_since_first_event: i64, }, App { - operation: &'static str, + operation: String, milliseconds_since_first_event: i64, }, Setting { @@ -129,6 +129,10 @@ pub enum Event { environment: &'static str, milliseconds_since_first_event: i64, }, + Button { + operation: &'static str, + milliseconds_since_first_event: i64, + }, } #[cfg(debug_assertions)] @@ -219,7 +223,7 @@ impl Telemetry { // TestAppContext ends up calling this function on shutdown and it panics when trying to find the TelemetrySettings #[cfg(not(any(test, feature = "test-support")))] fn shutdown_telemetry(self: &Arc) -> impl Future { - self.report_app_event("close"); + self.report_app_event("close".to_string()); // TODO: close final edit period and make sure it's sent Task::ready(()) } @@ -385,7 +389,7 @@ impl Telemetry { self.report_event(event) } - pub fn report_app_event(self: &Arc, operation: &'static str) { + pub fn report_app_event(self: &Arc, operation: String) { let event = Event::App { operation, milliseconds_since_first_event: self.milliseconds_since_first_event(), @@ -404,20 +408,6 @@ impl Telemetry { self.report_event(event) } - fn milliseconds_since_first_event(&self) -> i64 { - let mut state = self.state.lock(); - match state.first_event_datetime { - Some(first_event_datetime) => { - let now: DateTime = Utc::now(); - now.timestamp_millis() - first_event_datetime.timestamp_millis() - } - None => { - state.first_event_datetime = Some(Utc::now()); - 0 - } - } - } - pub fn log_edit_event(self: &Arc, environment: &'static str) { let mut state = self.state.lock(); let period_data = state.event_coalescer.log_event(environment); @@ -434,6 +424,30 @@ impl Telemetry { } } + pub fn report_button_event(self: &Arc, operation: &'static str) { + let event = Event::Button { + operation, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_event(event) + } + + fn milliseconds_since_first_event(&self) -> i64 { + let mut state = self.state.lock(); + + match state.first_event_datetime { + Some(first_event_datetime) => { + let now: DateTime = Utc::now(); + now.timestamp_millis() - first_event_datetime.timestamp_millis() + } + None => { + state.first_event_datetime = Some(Utc::now()); + 0 + } + } + } + fn report_event(self: &Arc, event: Event) { let mut state = self.state.lock(); diff --git a/crates/collab_ui/src/channel_view.rs b/crates/collab_ui/src/channel_view.rs index ce68acfbd8..033889f771 100644 --- a/crates/collab_ui/src/channel_view.rs +++ b/crates/collab_ui/src/channel_view.rs @@ -266,6 +266,10 @@ impl Item for ChannelView { .into_any_element() } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn clone_on_split(&self, _: WorkspaceId, cx: &mut ViewContext) -> Option> { Some(cx.new_view(|cx| { Self::new( diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index d88a8b7c23..ca701e626e 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -688,6 +688,10 @@ impl Item for ProjectDiagnosticsEditor { } } + fn telemetry_event_text(&self) -> Option<&'static str> { + Some("project diagnostics") + } + fn for_each_project_item( &self, cx: &AppContext, diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rs index ec91053629..36a48b2937 100644 --- a/crates/editor/src/items.rs +++ b/crates/editor/src/items.rs @@ -578,6 +578,10 @@ impl Item for Editor { Some(file_path.into()) } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn tab_description<'a>(&self, detail: usize, cx: &'a AppContext) -> Option { let path = path_for_buffer(&self.buffer, detail, true, cx)?; Some(path.to_string_lossy().to_string().into()) diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index 0720c53cbc..75b4305b58 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -631,6 +631,10 @@ impl Item for LspLogView { .into_any_element() } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn as_searchable(&self, handle: &View) -> Option> { Some(Box::new(handle.clone())) } diff --git a/crates/language_tools/src/syntax_tree_view.rs b/crates/language_tools/src/syntax_tree_view.rs index bfe2b2a03b..5acc6bff7f 100644 --- a/crates/language_tools/src/syntax_tree_view.rs +++ b/crates/language_tools/src/syntax_tree_view.rs @@ -397,6 +397,10 @@ impl Item for SyntaxTreeView { .into_any_element() } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn clone_on_split( &self, _: workspace::WorkspaceId, diff --git a/crates/search/src/project_search.rs b/crates/search/src/project_search.rs index d0679ed0ee..3827b46c67 100644 --- a/crates/search/src/project_search.rs +++ b/crates/search/src/project_search.rs @@ -446,6 +446,10 @@ impl Item for ProjectSearchView { .into_any() } + fn telemetry_event_text(&self) -> Option<&'static str> { + Some("project search") + } + fn for_each_project_item( &self, cx: &AppContext, diff --git a/crates/terminal_view/src/terminal_view.rs b/crates/terminal_view/src/terminal_view.rs index b786877608..db4b21627f 100644 --- a/crates/terminal_view/src/terminal_view.rs +++ b/crates/terminal_view/src/terminal_view.rs @@ -708,6 +708,10 @@ impl Item for TerminalView { .into_any() } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn clone_on_split( &self, _workspace_id: WorkspaceId, diff --git a/crates/welcome/src/welcome.rs b/crates/welcome/src/welcome.rs index cefedeb73f..677b57a022 100644 --- a/crates/welcome/src/welcome.rs +++ b/crates/welcome/src/welcome.rs @@ -86,7 +86,7 @@ impl Render for WelcomePage { .full_width() .on_click(cx.listener(|this, _, cx| { this.telemetry - .report_app_event("welcome page: change theme"); + .report_app_event("welcome page: change theme".to_string()); this.workspace .update(cx, |workspace, cx| { theme_selector::toggle( @@ -102,8 +102,9 @@ impl Render for WelcomePage { Button::new("choose-keymap", "Choose a keymap") .full_width() .on_click(cx.listener(|this, _, cx| { - this.telemetry - .report_app_event("welcome page: change keymap"); + this.telemetry.report_app_event( + "welcome page: change keymap".to_string(), + ); this.workspace .update(cx, |workspace, cx| { base_keymap_picker::toggle( @@ -119,7 +120,8 @@ impl Render for WelcomePage { Button::new("install-cli", "Install the CLI") .full_width() .on_click(cx.listener(|this, _, cx| { - this.telemetry.report_app_event("welcome page: install cli"); + this.telemetry + .report_app_event("welcome page: install cli".to_string()); cx.app_mut() .spawn( |cx| async move { install_cli::install_cli(&cx).await }, @@ -150,8 +152,9 @@ impl Render for WelcomePage { ) .on_click(cx.listener( move |this, selection, cx| { - this.telemetry - .report_app_event("welcome page: toggle vim"); + this.telemetry.report_app_event( + "welcome page: toggle vim".to_string(), + ); this.update_settings::( selection, cx, @@ -177,7 +180,7 @@ impl Render for WelcomePage { .on_click(cx.listener( move |this, selection, cx| { this.telemetry.report_app_event( - "welcome page: toggle metric telemetry", + "welcome page: toggle metric telemetry".to_string(), ); this.update_settings::( selection, @@ -215,7 +218,8 @@ impl Render for WelcomePage { .on_click(cx.listener( move |this, selection, cx| { this.telemetry.report_app_event( - "welcome page: toggle diagnostic telemetry", + "welcome page: toggle diagnostic telemetry" + .to_string(), ); this.update_settings::( selection, @@ -247,7 +251,8 @@ impl WelcomePage { pub fn new(workspace: &Workspace, cx: &mut ViewContext) -> View { let this = cx.new_view(|cx| { cx.on_release(|this: &mut Self, _, _| { - this.telemetry.report_app_event("welcome page: close"); + this.telemetry + .report_app_event("welcome page: close".to_string()); }) .detach(); @@ -306,6 +311,10 @@ impl Item for WelcomePage { .into_any_element() } + fn telemetry_event_text(&self) -> Option<&'static str> { + Some("welcome page") + } + fn show_toolbar(&self) -> bool { false } diff --git a/crates/workspace/src/item.rs b/crates/workspace/src/item.rs index fb4ed05f6c..4f696e4a33 100644 --- a/crates/workspace/src/item.rs +++ b/crates/workspace/src/item.rs @@ -114,6 +114,8 @@ pub trait Item: FocusableView + EventEmitter { } fn tab_content(&self, detail: Option, selected: bool, cx: &WindowContext) -> AnyElement; + fn telemetry_event_text(&self) -> Option<&'static str>; + /// (model id, Item) fn for_each_project_item( &self, @@ -225,6 +227,7 @@ pub trait ItemHandle: 'static + Send { fn tab_tooltip_text(&self, cx: &AppContext) -> Option; fn tab_description(&self, detail: usize, cx: &AppContext) -> Option; fn tab_content(&self, detail: Option, selected: bool, cx: &WindowContext) -> AnyElement; + fn telemetry_event_text(&self, cx: &WindowContext) -> Option<&'static str>; fn dragged_tab_content(&self, detail: Option, cx: &WindowContext) -> AnyElement; fn project_path(&self, cx: &AppContext) -> Option; fn project_entry_ids(&self, cx: &AppContext) -> SmallVec<[ProjectEntryId; 3]>; @@ -313,6 +316,10 @@ impl ItemHandle for View { self.read(cx).tab_tooltip_text(cx) } + fn telemetry_event_text(&self, cx: &WindowContext) -> Option<&'static str> { + self.read(cx).telemetry_event_text() + } + fn tab_description(&self, detail: usize, cx: &AppContext) -> Option { self.read(cx).tab_description(detail, cx) } @@ -922,6 +929,10 @@ pub mod test { }) } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn tab_content( &self, detail: Option, diff --git a/crates/workspace/src/shared_screen.rs b/crates/workspace/src/shared_screen.rs index 6fb156c22f..bfc1602274 100644 --- a/crates/workspace/src/shared_screen.rs +++ b/crates/workspace/src/shared_screen.rs @@ -111,6 +111,10 @@ impl Item for SharedScreen { .into_any() } + fn telemetry_event_text(&self) -> Option<&'static str> { + None + } + fn set_nav_history(&mut self, history: ItemNavHistory, _: &mut ViewContext) { self.nav_history = Some(history); } diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rs index efd2c52989..2bbcfa80a2 100644 --- a/crates/workspace/src/workspace.rs +++ b/crates/workspace/src/workspace.rs @@ -1271,7 +1271,9 @@ impl Workspace { } pub fn open(&mut self, _: &Open, cx: &mut ViewContext) { - self.client().telemetry().report_app_event("open project"); + self.client() + .telemetry() + .report_app_event("open project".to_string()); let paths = cx.prompt_for_paths(PathPromptOptions { files: true, directories: true, @@ -1776,6 +1778,14 @@ impl Workspace { } pub fn add_item(&mut self, item: Box, cx: &mut ViewContext) { + if let Some(text) = item.telemetry_event_text(cx) { + dbg!("workspace"); + dbg!(&text); + self.client() + .telemetry() + .report_app_event(format!("{}: open", text)); + } + self.active_pane .update(cx, |pane, cx| pane.add_item(item, true, true, None, cx)); } diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index e10c52a175..821668001c 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -176,10 +176,13 @@ fn main() { telemetry.start(installation_id, session_id, cx); telemetry.report_setting_event("theme", cx.theme().name.to_string()); telemetry.report_setting_event("keymap", BaseKeymap::get_global(cx).to_string()); - telemetry.report_app_event(match existing_installation_id_found { - Some(false) => "first open", - _ => "open", - }); + telemetry.report_app_event( + match existing_installation_id_found { + Some(false) => "first open", + _ => "open", + } + .to_string(), + ); telemetry.flush_events(); let app_state = Arc::new(AppState {