Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Remove immediate flush mode
Joseph T. Lyons5344296c9a63
diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rsindex 076ac15710d..d0a92b681d5 100644--- a/crates/client/src/telemetry.rs+++ b/crates/client/src/telemetry.rs@@ -193,7 +193,8 @@ 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<Self>) -> impl Future<Output = ()> {- self.report_app_event("close", true);+ self.report_app_event("close");+ self.flush_clickhouse_events();Task::ready(())}@@ -283,7 +284,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}pub fn report_copilot_event(@@ -299,7 +300,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}pub fn report_assistant_event(@@ -315,7 +316,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}pub fn report_call_event(@@ -331,7 +332,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}pub fn report_cpu_event(self: &Arc<Self>, usage_as_percentage: f32, core_count: u32) {@@ -341,7 +342,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}pub fn report_memory_event(@@ -355,16 +356,16 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}- pub fn report_app_event(self: &Arc<Self>, operation: &'static str, immediate_flush: bool) {+ pub fn report_app_event(self: &Arc<Self>, operation: &'static str) {let event = ClickhouseEvent::App {operation,milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, immediate_flush)+ self.report_clickhouse_event(event)}pub fn report_setting_event(self: &Arc<Self>, setting: &'static str, value: String) {@@ -374,7 +375,7 @@ impl Telemetry {milliseconds_since_first_event: self.milliseconds_since_first_event(),};- self.report_clickhouse_event(event, false)+ self.report_clickhouse_event(event)}fn milliseconds_since_first_event(&self) -> i64 {@@ -391,7 +392,7 @@ impl Telemetry {}}- fn report_clickhouse_event(self: &Arc<Self>, event: ClickhouseEvent, immediate_flush: bool) {+ fn report_clickhouse_event(self: &Arc<Self>, event: ClickhouseEvent) {let mut state = self.state.lock();if !state.settings.metrics {@@ -404,7 +405,7 @@ impl Telemetry {.push(ClickhouseEventWrapper { signed_in, event });if state.installation_id.is_some() {- if immediate_flush || state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {+ if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN {drop(state);self.flush_clickhouse_events();} else {@@ -430,7 +431,7 @@ impl Telemetry {self.state.lock().is_staff}- fn flush_clickhouse_events(self: &Arc<Self>) {+ pub fn flush_clickhouse_events(self: &Arc<Self>) {let mut state = self.state.lock();state.first_event_datetime = None;let mut events = mem::take(&mut state.clickhouse_events_queue);diff --git a/crates/welcome/src/welcome.rs b/crates/welcome/src/welcome.rsindex 1c0b7472085..3d898106792 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 button: theme", false);+ .report_app_event("welcome page button: theme");this.workspace.update(cx, |workspace, cx| {theme_selector::toggle(@@ -103,7 +103,7 @@ impl Render for WelcomePage {.full_width().on_click(cx.listener(|this, _, cx| {this.telemetry- .report_app_event("welcome page button: keymap", false);+ .report_app_event("welcome page button: keymap");this.workspace.update(cx, |workspace, cx| {base_keymap_picker::toggle(@@ -119,10 +119,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 button: install cli",- false,- );+ this.telemetry+ .report_app_event("welcome page button: install cli");cx.app_mut().spawn(|cx| async move { install_cli::install_cli(&cx).await },@@ -153,10 +151,8 @@ impl Render for WelcomePage {).on_click(cx.listener(move |this, selection, cx| {- this.telemetry.report_app_event(- "welcome page button: vim",- false,- );+ this.telemetry+ .report_app_event("welcome page button: vim");this.update_settings::<VimModeSetting>(selection,cx,@@ -183,7 +179,6 @@ impl Render for WelcomePage {move |this, selection, cx| {this.telemetry.report_app_event("welcome page button: user telemetry",- false,);this.update_settings::<TelemetrySettings>(selection,@@ -222,7 +217,6 @@ impl Render for WelcomePage {move |this, selection, cx| {this.telemetry.report_app_event("welcome page button: crash diagnostics",- false,);this.update_settings::<TelemetrySettings>(selection,@@ -254,7 +248,7 @@ impl WelcomePage {pub fn new(workspace: &Workspace, cx: &mut ViewContext<Workspace>) -> View<Self> {let this = cx.new_view(|cx| {cx.on_release(|this: &mut Self, _, _| {- this.telemetry.report_app_event("close welcome page", false);+ this.telemetry.report_app_event("close welcome page");}).detach();diff --git a/crates/workspace/src/workspace.rs b/crates/workspace/src/workspace.rsindex 653f7770842..967e76efd65 100644--- a/crates/workspace/src/workspace.rs+++ b/crates/workspace/src/workspace.rs@@ -1258,9 +1258,7 @@ impl Workspace {}pub fn open(&mut self, _: &Open, cx: &mut ViewContext<Self>) {- self.client()- .telemetry()- .report_app_event("open project", false);+ self.client().telemetry().report_app_event("open project");let paths = cx.prompt_for_paths(PathPromptOptions {files: true,directories: true,diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rsindex 22436e10a97..ff07af03bd8 100644--- a/crates/zed/src/main.rs+++ b/crates/zed/src/main.rs@@ -175,13 +175,11 @@ 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",- },- true,- );+ telemetry.report_app_event(match existing_installation_id_found {+ Some(false) => "first open",+ _ => "open",+ });+ telemetry.flush_clickhouse_events();let app_state = Arc::new(AppState {languages: languages.clone(),