From 3abd376d6ad9d175919d47b75767a737aefe67de Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sun, 19 Nov 2023 21:52:28 -0500 Subject: [PATCH 1/6] Add timestamp delta to telemetry events --- Cargo.lock | 2 + crates/assistant/src/assistant_panel.rs | 14 +- crates/call/src/call.rs | 23 ++-- crates/call2/src/call2.rs | 23 ++-- crates/client/Cargo.toml | 1 + crates/client/src/telemetry.rs | 165 ++++++++++++++++++++--- crates/client2/Cargo.toml | 1 + crates/client2/src/telemetry.rs | 168 +++++++++++++++++++++--- crates/editor/src/editor.rs | 14 +- crates/editor2/src/editor.rs | 16 +-- crates/zed/src/main.rs | 6 +- crates/zed2/src/main.rs | 9 +- 12 files changed, 343 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc045354f940f698954fb71e221c187f6b034a10..9ecae828102ee3a1526beb196a7a28b94775a8d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1550,6 +1550,7 @@ dependencies = [ "anyhow", "async-recursion 0.3.2", "async-tungstenite", + "chrono", "collections", "db", "feature_flags", @@ -1586,6 +1587,7 @@ dependencies = [ "anyhow", "async-recursion 0.3.2", "async-tungstenite", + "chrono", "collections", "db2", "feature_flags2", diff --git a/crates/assistant/src/assistant_panel.rs b/crates/assistant/src/assistant_panel.rs index 6ab96093a74e3f30ee44b21c396eb76a41a1e179..cac8bf6c54f8b335df756c13b08fb056b6378dd5 100644 --- a/crates/assistant/src/assistant_panel.rs +++ b/crates/assistant/src/assistant_panel.rs @@ -15,7 +15,7 @@ use ai::{ use ai::prompts::repository_context::PromptCodeSnippet; use anyhow::{anyhow, Result}; use chrono::{DateTime, Local}; -use client::{telemetry::AssistantKind, ClickhouseEvent, TelemetrySettings}; +use client::{telemetry::AssistantKind, TelemetrySettings}; use collections::{hash_map, HashMap, HashSet, VecDeque}; use editor::{ display_map::{ @@ -3803,12 +3803,12 @@ fn report_assistant_event( .default_open_ai_model .clone(); - let event = ClickhouseEvent::Assistant { - conversation_id, - kind: assistant_kind, - model: model.full_name(), - }; let telemetry_settings = *settings::get::(cx); - telemetry.report_clickhouse_event(event, telemetry_settings) + telemetry.report_assistant_event( + telemetry_settings, + conversation_id, + assistant_kind, + model.full_name(), + ) } diff --git a/crates/call/src/call.rs b/crates/call/src/call.rs index ca1a60bd631c885924da7e6a8ca8b3c5ce2aa114..7959a8c7d18b24dac1259cde21a1abec4105f1ba 100644 --- a/crates/call/src/call.rs +++ b/crates/call/src/call.rs @@ -5,10 +5,7 @@ pub mod room; use anyhow::{anyhow, Result}; use audio::Audio; use call_settings::CallSettings; -use client::{ - proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore, - ZED_ALWAYS_ACTIVE, -}; +use client::{proto, Client, TelemetrySettings, TypedEnvelope, User, UserStore, ZED_ALWAYS_ACTIVE}; use collections::HashSet; use futures::{channel::oneshot, future::Shared, Future, FutureExt}; use gpui::{ @@ -485,12 +482,8 @@ pub fn report_call_event_for_room( ) { let telemetry = client.telemetry(); let telemetry_settings = *settings::get::(cx); - let event = ClickhouseEvent::Call { - operation, - room_id: Some(room_id), - channel_id, - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + + telemetry.report_call_event(telemetry_settings, operation, Some(room_id), channel_id) } pub fn report_call_event_for_channel( @@ -504,12 +497,12 @@ pub fn report_call_event_for_channel( let telemetry = client.telemetry(); let telemetry_settings = *settings::get::(cx); - let event = ClickhouseEvent::Call { + telemetry.report_call_event( + telemetry_settings, operation, - room_id: room.map(|r| r.read(cx).id()), - channel_id: Some(channel_id), - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + room.map(|r| r.read(cx).id()), + Some(channel_id), + ) } #[cfg(test)] diff --git a/crates/call2/src/call2.rs b/crates/call2/src/call2.rs index 2fab3d40ce600c0b9c26cbc31b95398cc1ab9a96..1f11e0650ddf3808adce0997afbce58cdc389819 100644 --- a/crates/call2/src/call2.rs +++ b/crates/call2/src/call2.rs @@ -5,10 +5,7 @@ pub mod room; use anyhow::{anyhow, Result}; use audio::Audio; use call_settings::CallSettings; -use client::{ - proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore, - ZED_ALWAYS_ACTIVE, -}; +use client::{proto, Client, TelemetrySettings, TypedEnvelope, User, UserStore, ZED_ALWAYS_ACTIVE}; use collections::HashSet; use futures::{channel::oneshot, future::Shared, Future, FutureExt}; use gpui::{ @@ -484,12 +481,8 @@ pub fn report_call_event_for_room( ) { let telemetry = client.telemetry(); let telemetry_settings = *TelemetrySettings::get_global(cx); - let event = ClickhouseEvent::Call { - operation, - room_id: Some(room_id), - channel_id, - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + + telemetry.report_call_event(telemetry_settings, operation, Some(room_id), channel_id) } pub fn report_call_event_for_channel( @@ -504,12 +497,12 @@ pub fn report_call_event_for_channel( let telemetry_settings = *TelemetrySettings::get_global(cx); - let event = ClickhouseEvent::Call { + telemetry.report_call_event( + telemetry_settings, operation, - room_id: room.map(|r| r.read(cx).id()), - channel_id: Some(channel_id), - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + room.map(|r| r.read(cx).id()), + Some(channel_id), + ) } #[cfg(test)] diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index c8085f807bd5786daa6e8579bdf263c978dd4e74..c24cbca35be25aeca198cd9178467bfb93db2969 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -12,6 +12,7 @@ doctest = false test-support = ["collections/test-support", "gpui/test-support", "rpc/test-support"] [dependencies] +chrono = { version = "0.4", features = ["serde"] } collections = { path = "../collections" } db = { path = "../db" } gpui = { path = "../gpui" } diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index ad2b29c3887731de0d5e477dc344154eba54d0d1..76953679bee7f70e97b35b9e963397935c086b4c 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -1,4 +1,5 @@ use crate::{TelemetrySettings, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL}; +use chrono::{DateTime, Utc}; use gpui::{executor::Background, serde_json, AppContext, Task}; use lazy_static::lazy_static; use parking_lot::Mutex; @@ -31,6 +32,7 @@ struct TelemetryState { flush_clickhouse_events_task: Option>, log_file: Option, is_staff: Option, + first_event_datetime: Option>, } const CLICKHOUSE_EVENTS_URL_PATH: &'static str = "/api/events"; @@ -77,42 +79,48 @@ pub enum ClickhouseEvent { vim_mode: bool, copilot_enabled: bool, copilot_enabled_for_language: bool, + milliseconds_since_first_event: i64, }, Copilot { suggestion_id: Option, suggestion_accepted: bool, file_extension: Option, + milliseconds_since_first_event: i64, }, Call { operation: &'static str, room_id: Option, channel_id: Option, + milliseconds_since_first_event: i64, }, Assistant { conversation_id: Option, kind: AssistantKind, model: &'static str, + milliseconds_since_first_event: i64, }, Cpu { usage_as_percentage: f32, core_count: u32, + milliseconds_since_first_event: i64, }, Memory { memory_in_bytes: u64, virtual_memory_in_bytes: u64, + milliseconds_since_first_event: i64, }, } -#[cfg(debug_assertions)] -const MAX_QUEUE_LEN: usize = 1; +// #[cfg(debug_assertions)] +// const MAX_QUEUE_LEN: usize = 1; -#[cfg(not(debug_assertions))] +// #[cfg(not(debug_assertions))] const MAX_QUEUE_LEN: usize = 10; -#[cfg(debug_assertions)] -const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); +// #[cfg(debug_assertions)] +// const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); -#[cfg(not(debug_assertions))] +// #[cfg(not(debug_assertions))] const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl Telemetry { @@ -140,6 +148,7 @@ impl Telemetry { flush_clickhouse_events_task: Default::default(), log_file: None, is_staff: None, + first_event_datetime: None, }), }); @@ -195,20 +204,18 @@ impl Telemetry { return; }; - let memory_event = ClickhouseEvent::Memory { - memory_in_bytes: process.memory(), - virtual_memory_in_bytes: process.virtual_memory(), - }; - - let cpu_event = ClickhouseEvent::Cpu { - usage_as_percentage: process.cpu_usage(), - core_count: system.cpus().len() as u32, - }; - let telemetry_settings = cx.update(|cx| *settings::get::(cx)); - this.report_clickhouse_event(memory_event, telemetry_settings); - this.report_clickhouse_event(cpu_event, telemetry_settings); + this.report_memory_event( + telemetry_settings, + process.memory(), + process.virtual_memory(), + ); + this.report_cpu_event( + telemetry_settings, + process.cpu_usage(), + system.cpus().len() as u32, + ); } }) .detach(); @@ -231,7 +238,123 @@ impl Telemetry { drop(state); } - pub fn report_clickhouse_event( + pub fn report_editor_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + file_extension: Option, + vim_mode: bool, + operation: &'static str, + copilot_enabled: bool, + copilot_enabled_for_language: bool, + ) { + let event = ClickhouseEvent::Editor { + file_extension, + vim_mode, + operation, + copilot_enabled, + copilot_enabled_for_language, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_copilot_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + suggestion_id: Option, + suggestion_accepted: bool, + file_extension: Option, + ) { + let event = ClickhouseEvent::Copilot { + suggestion_id, + suggestion_accepted, + file_extension, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_assistant_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + conversation_id: Option, + kind: AssistantKind, + model: &'static str, + ) { + let event = ClickhouseEvent::Assistant { + conversation_id, + kind, + model, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_call_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + operation: &'static str, + room_id: Option, + channel_id: Option, + ) { + let event = ClickhouseEvent::Call { + operation, + room_id, + channel_id, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_cpu_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + usage_as_percentage: f32, + core_count: u32, + ) { + let event = ClickhouseEvent::Cpu { + usage_as_percentage, + core_count, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_memory_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + memory_in_bytes: u64, + virtual_memory_in_bytes: u64, + ) { + let event = ClickhouseEvent::Memory { + memory_in_bytes, + virtual_memory_in_bytes, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + 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_clickhouse_event( self: &Arc, event: ClickhouseEvent, telemetry_settings: TelemetrySettings, @@ -246,6 +369,8 @@ impl Telemetry { .clickhouse_events_queue .push(ClickhouseEventWrapper { signed_in, event }); + dbg!(state.clickhouse_events_queue.len(), chrono::Utc::now()); + if state.installation_id.is_some() { if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN { drop(state); @@ -275,6 +400,7 @@ impl Telemetry { fn flush_clickhouse_events(self: &Arc) { let mut state = self.state.lock(); + state.first_event_datetime = None; let mut events = mem::take(&mut state.clickhouse_events_queue); state.flush_clickhouse_events_task.take(); drop(state); @@ -310,6 +436,7 @@ impl Telemetry { release_channel: state.release_channel, events, }; + dbg!(&request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; } diff --git a/crates/client2/Cargo.toml b/crates/client2/Cargo.toml index ace229bc210a41243d3c59f6c8add3d4a63ce729..b1c993e3a49c41ccfb0da866508c188241e45f3b 100644 --- a/crates/client2/Cargo.toml +++ b/crates/client2/Cargo.toml @@ -12,6 +12,7 @@ doctest = false test-support = ["collections/test-support", "gpui/test-support", "rpc/test-support"] [dependencies] +chrono = { version = "0.4", features = ["serde"] } collections = { path = "../collections" } db = { package = "db2", path = "../db2" } gpui = { package = "gpui2", path = "../gpui2" } diff --git a/crates/client2/src/telemetry.rs b/crates/client2/src/telemetry.rs index cf5b3b765bcade42878be3746c63f827e611d160..d5d6d06213d92ab12678f617006be9ac1ee03727 100644 --- a/crates/client2/src/telemetry.rs +++ b/crates/client2/src/telemetry.rs @@ -1,4 +1,5 @@ use crate::{TelemetrySettings, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL}; +use chrono::{DateTime, Utc}; use gpui::{serde_json, AppContext, AppMetadata, BackgroundExecutor, Task}; use lazy_static::lazy_static; use parking_lot::Mutex; @@ -29,6 +30,7 @@ struct TelemetryState { flush_clickhouse_events_task: Option>, log_file: Option, is_staff: Option, + first_event_datetime: Option>, } const CLICKHOUSE_EVENTS_URL_PATH: &'static str = "/api/events"; @@ -75,42 +77,48 @@ pub enum ClickhouseEvent { vim_mode: bool, copilot_enabled: bool, copilot_enabled_for_language: bool, + milliseconds_since_first_event: i64, }, Copilot { suggestion_id: Option, suggestion_accepted: bool, file_extension: Option, + milliseconds_since_first_event: i64, }, Call { operation: &'static str, room_id: Option, channel_id: Option, + milliseconds_since_first_event: i64, }, Assistant { conversation_id: Option, kind: AssistantKind, model: &'static str, + milliseconds_since_first_event: i64, }, Cpu { usage_as_percentage: f32, core_count: u32, + milliseconds_since_first_event: i64, }, Memory { memory_in_bytes: u64, virtual_memory_in_bytes: u64, + milliseconds_since_first_event: i64, }, } -#[cfg(debug_assertions)] -const MAX_QUEUE_LEN: usize = 1; +// #[cfg(debug_assertions)] +// const MAX_QUEUE_LEN: usize = 1; -#[cfg(not(debug_assertions))] +// #[cfg(not(debug_assertions))] const MAX_QUEUE_LEN: usize = 10; -#[cfg(debug_assertions)] -const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); +// #[cfg(debug_assertions)] +// const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); -#[cfg(not(debug_assertions))] +// #[cfg(not(debug_assertions))] const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl Telemetry { @@ -135,6 +143,7 @@ impl Telemetry { flush_clickhouse_events_task: Default::default(), log_file: None, is_staff: None, + first_event_datetime: None, }), }); @@ -190,16 +199,6 @@ impl Telemetry { return; }; - let memory_event = ClickhouseEvent::Memory { - memory_in_bytes: process.memory(), - virtual_memory_in_bytes: process.virtual_memory(), - }; - - let cpu_event = ClickhouseEvent::Cpu { - usage_as_percentage: process.cpu_usage(), - core_count: system.cpus().len() as u32, - }; - let telemetry_settings = if let Ok(telemetry_settings) = cx.update(|cx| *TelemetrySettings::get_global(cx)) { @@ -208,8 +207,16 @@ impl Telemetry { break; }; - this.report_clickhouse_event(memory_event, telemetry_settings); - this.report_clickhouse_event(cpu_event, telemetry_settings); + this.report_memory_event( + telemetry_settings, + process.memory(), + process.virtual_memory(), + ); + this.report_cpu_event( + telemetry_settings, + process.cpu_usage(), + system.cpus().len() as u32, + ); } }) .detach(); @@ -232,7 +239,123 @@ impl Telemetry { drop(state); } - pub fn report_clickhouse_event( + pub fn report_editor_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + file_extension: Option, + vim_mode: bool, + operation: &'static str, + copilot_enabled: bool, + copilot_enabled_for_language: bool, + ) { + let event = ClickhouseEvent::Editor { + file_extension, + vim_mode, + operation, + copilot_enabled, + copilot_enabled_for_language, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_copilot_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + suggestion_id: Option, + suggestion_accepted: bool, + file_extension: Option, + ) { + let event = ClickhouseEvent::Copilot { + suggestion_id, + suggestion_accepted, + file_extension, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_assistant_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + conversation_id: Option, + kind: AssistantKind, + model: &'static str, + ) { + let event = ClickhouseEvent::Assistant { + conversation_id, + kind, + model, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_call_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + operation: &'static str, + room_id: Option, + channel_id: Option, + ) { + let event = ClickhouseEvent::Call { + operation, + room_id, + channel_id, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_cpu_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + usage_as_percentage: f32, + core_count: u32, + ) { + let event = ClickhouseEvent::Cpu { + usage_as_percentage, + core_count, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + pub fn report_memory_event( + self: &Arc, + telemetry_settings: TelemetrySettings, + memory_in_bytes: u64, + virtual_memory_in_bytes: u64, + ) { + let event = ClickhouseEvent::Memory { + memory_in_bytes, + virtual_memory_in_bytes, + milliseconds_since_first_event: self.milliseconds_since_first_event(), + }; + + self.report_clickhouse_event(event, telemetry_settings) + } + + 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_clickhouse_event( self: &Arc, event: ClickhouseEvent, telemetry_settings: TelemetrySettings, @@ -247,6 +370,9 @@ impl Telemetry { .clickhouse_events_queue .push(ClickhouseEventWrapper { signed_in, event }); + dbg!(state.clickhouse_events_queue.len(), chrono::Utc::now()); + dbg!(state.installation_id.is_some()); + if state.installation_id.is_some() { if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN { drop(state); @@ -276,10 +402,13 @@ impl Telemetry { fn flush_clickhouse_events(self: &Arc) { let mut state = self.state.lock(); + state.first_event_datetime = None; let mut events = mem::take(&mut state.clickhouse_events_queue); state.flush_clickhouse_events_task.take(); drop(state); + dbg!("In flush"); + let this = self.clone(); self.executor .spawn( @@ -317,6 +446,7 @@ impl Telemetry { release_channel: state.release_channel, events, }; + dbg!(&request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; } diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 4e449bb7f7732c8d65968c3723d800e29278e748..2558aec12139843135cc59c7b6ff516750c89a42 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -24,7 +24,7 @@ use ::git::diff::DiffHunk; use aho_corasick::AhoCorasick; use anyhow::{anyhow, Context, Result}; use blink_manager::BlinkManager; -use client::{ClickhouseEvent, Client, Collaborator, ParticipantIndex, TelemetrySettings}; +use client::{Client, Collaborator, ParticipantIndex, TelemetrySettings}; use clock::{Global, ReplicaId}; use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque}; use convert_case::{Case, Casing}; @@ -8946,12 +8946,12 @@ impl Editor { let telemetry = project.read(cx).client().telemetry().clone(); let telemetry_settings = *settings::get::(cx); - let event = ClickhouseEvent::Copilot { + telemetry.report_copilot_event( + telemetry_settings, suggestion_id, suggestion_accepted, file_extension, - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + ) } #[cfg(any(test, feature = "test-support"))] @@ -8998,14 +8998,14 @@ impl Editor { .show_copilot_suggestions; let telemetry = project.read(cx).client().telemetry().clone(); - let event = ClickhouseEvent::Editor { + telemetry.report_editor_event( + telemetry_settings, file_extension, vim_mode, operation, copilot_enabled, copilot_enabled_for_language, - }; - telemetry.report_clickhouse_event(event, telemetry_settings) + ) } /// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines, diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index beed93e91761566400b8a3d8bb0ae92dd786ed4a..dc83c02b96d8b74b89219c71ad46526e15c7bf6e 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -24,7 +24,7 @@ use ::git::diff::DiffHunk; use aho_corasick::AhoCorasick; use anyhow::{anyhow, Context as _, Result}; use blink_manager::BlinkManager; -use client::{ClickhouseEvent, Client, Collaborator, ParticipantIndex, TelemetrySettings}; +use client::{Client, Collaborator, ParticipantIndex, TelemetrySettings}; use clock::ReplicaId; use collections::{BTreeMap, Bound, HashMap, HashSet, VecDeque}; use convert_case::{Case, Casing}; @@ -8968,12 +8968,12 @@ impl Editor { let telemetry = project.read(cx).client().telemetry().clone(); let telemetry_settings = *TelemetrySettings::get_global(cx); - let event = ClickhouseEvent::Copilot { + telemetry.report_copilot_event( + telemetry_settings, suggestion_id, suggestion_accepted, file_extension, - }; - telemetry.report_clickhouse_event(event, telemetry_settings); + ) } #[cfg(any(test, feature = "test-support"))] @@ -8985,7 +8985,7 @@ impl Editor { ) { } - #[cfg(not(any(test, feature = "test-support")))] + // #[cfg(not(any(test, feature = "test-support")))] fn report_editor_event( &self, operation: &'static str, @@ -9020,14 +9020,14 @@ impl Editor { .show_copilot_suggestions; let telemetry = project.read(cx).client().telemetry().clone(); - let event = ClickhouseEvent::Editor { + telemetry.report_editor_event( + telemetry_settings, file_extension, vim_mode, operation, copilot_enabled, copilot_enabled_for_language, - }; - telemetry.report_clickhouse_event(event, telemetry_settings) + ) } /// Copy the highlighted chunks to the clipboard as JSON. The format is an array of lines, diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 0cdedd67458ed311c91aaf6a5e95dcc98484a0df..0e7bd5c3c8abce5f8ff6ff553524cd83bd177432 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -3,6 +3,7 @@ use anyhow::{anyhow, Context, Result}; use backtrace::Backtrace; +use chrono::{DateTime, Utc}; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use client::{ self, Client, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN, @@ -490,10 +491,7 @@ fn init_panic_hook(app: &App, installation_id: Option, session_id: Strin .ok() .map(|os_version| os_version.to_string()), architecture: env::consts::ARCH.into(), - panicked_on: SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis(), + panicked_on: Utc::now().timestamp_millis(), backtrace, installation_id: installation_id.clone(), session_id: session_id.clone(), diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 6c402514d2c7a8f703ea25a1746787aedf1cb961..69e0e2b37d373d19687fb37f6916bb2724eabf8b 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -6,6 +6,7 @@ use anyhow::{anyhow, Context as _, Result}; use backtrace::Backtrace; +use chrono::{DateTime, Utc}; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use client::UserStore; use db::kvp::KEY_VALUE_STORE; @@ -72,6 +73,7 @@ fn main() { let app = App::production(Arc::new(Assets)); let installation_id = app.background_executor().block(installation_id()).ok(); + dbg!("HERE", &installation_id); let session_id = Uuid::new_v4().to_string(); init_panic_hook(&app, installation_id.clone(), session_id.clone()); @@ -172,7 +174,7 @@ fn main() { // }) // .detach(); - // client.telemetry().start(installation_id, session_id, cx); + client.telemetry().start(installation_id, session_id, cx); let app_state = Arc::new(AppState { languages, @@ -514,10 +516,7 @@ fn init_panic_hook(app: &App, installation_id: Option, session_id: Strin .as_ref() .map(SemanticVersion::to_string), architecture: env::consts::ARCH.into(), - panicked_on: SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis(), + panicked_on: Utc::now().timestamp_millis(), backtrace, installation_id: installation_id.clone(), session_id: session_id.clone(), From e0f8615d52bfbddb8463fac79cd7f48f79ac3a3d Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sun, 19 Nov 2023 21:55:19 -0500 Subject: [PATCH 2/6] Remoe `dbg!()`s --- crates/client/src/telemetry.rs | 3 --- crates/client2/src/telemetry.rs | 6 ------ crates/zed2/src/main.rs | 1 - 3 files changed, 10 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 76953679bee7f70e97b35b9e963397935c086b4c..9319d1d84104e699c6520d91fb0cd8fee1faa465 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -369,8 +369,6 @@ impl Telemetry { .clickhouse_events_queue .push(ClickhouseEventWrapper { signed_in, event }); - dbg!(state.clickhouse_events_queue.len(), chrono::Utc::now()); - if state.installation_id.is_some() { if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN { drop(state); @@ -436,7 +434,6 @@ impl Telemetry { release_channel: state.release_channel, events, }; - dbg!(&request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; } diff --git a/crates/client2/src/telemetry.rs b/crates/client2/src/telemetry.rs index d5d6d06213d92ab12678f617006be9ac1ee03727..5020caa6f86553580938fde5ccd927cae47d9469 100644 --- a/crates/client2/src/telemetry.rs +++ b/crates/client2/src/telemetry.rs @@ -370,9 +370,6 @@ impl Telemetry { .clickhouse_events_queue .push(ClickhouseEventWrapper { signed_in, event }); - dbg!(state.clickhouse_events_queue.len(), chrono::Utc::now()); - dbg!(state.installation_id.is_some()); - if state.installation_id.is_some() { if state.clickhouse_events_queue.len() >= MAX_QUEUE_LEN { drop(state); @@ -407,8 +404,6 @@ impl Telemetry { state.flush_clickhouse_events_task.take(); drop(state); - dbg!("In flush"); - let this = self.clone(); self.executor .spawn( @@ -446,7 +441,6 @@ impl Telemetry { release_channel: state.release_channel, events, }; - dbg!(&request_body); json_bytes.clear(); serde_json::to_writer(&mut json_bytes, &request_body)?; } diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 69e0e2b37d373d19687fb37f6916bb2724eabf8b..9f17332474d6aa861253ca7a24dda18b7fedb344 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -73,7 +73,6 @@ fn main() { let app = App::production(Arc::new(Assets)); let installation_id = app.background_executor().block(installation_id()).ok(); - dbg!("HERE", &installation_id); let session_id = Uuid::new_v4().to_string(); init_panic_hook(&app, installation_id.clone(), session_id.clone()); From 8e612e4287b0bbb7fe5a49ad30c8ace57fac4c57 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sun, 19 Nov 2023 21:58:42 -0500 Subject: [PATCH 3/6] Restore commented-out code --- crates/client/src/telemetry.rs | 12 ++++++------ crates/client2/src/telemetry.rs | 12 ++++++------ crates/editor2/src/editor.rs | 2 +- crates/zed2/src/main.rs | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 9319d1d84104e699c6520d91fb0cd8fee1faa465..8f7fbeb83d3e974aadcbc64dbee0f3d5482242cd 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -111,16 +111,16 @@ pub enum ClickhouseEvent { }, } -// #[cfg(debug_assertions)] -// const MAX_QUEUE_LEN: usize = 1; +#[cfg(debug_assertions)] +const MAX_QUEUE_LEN: usize = 1; -// #[cfg(not(debug_assertions))] +#[cfg(not(debug_assertions))] const MAX_QUEUE_LEN: usize = 10; -// #[cfg(debug_assertions)] -// const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); +#[cfg(debug_assertions)] +const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); -// #[cfg(not(debug_assertions))] +#[cfg(not(debug_assertions))] const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl Telemetry { diff --git a/crates/client2/src/telemetry.rs b/crates/client2/src/telemetry.rs index 5020caa6f86553580938fde5ccd927cae47d9469..9c88d1102c255d6892212e6e28d5346e5b55b3fd 100644 --- a/crates/client2/src/telemetry.rs +++ b/crates/client2/src/telemetry.rs @@ -109,16 +109,16 @@ pub enum ClickhouseEvent { }, } -// #[cfg(debug_assertions)] -// const MAX_QUEUE_LEN: usize = 1; +#[cfg(debug_assertions)] +const MAX_QUEUE_LEN: usize = 1; -// #[cfg(not(debug_assertions))] +#[cfg(not(debug_assertions))] const MAX_QUEUE_LEN: usize = 10; -// #[cfg(debug_assertions)] -// const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); +#[cfg(debug_assertions)] +const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(1); -// #[cfg(not(debug_assertions))] +#[cfg(not(debug_assertions))] const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl Telemetry { diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index dc83c02b96d8b74b89219c71ad46526e15c7bf6e..be621bc5f6acb91baf088ac31ce62fd83888df8f 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -8985,7 +8985,7 @@ impl Editor { ) { } - // #[cfg(not(any(test, feature = "test-support")))] + #[cfg(not(any(test, feature = "test-support")))] fn report_editor_event( &self, operation: &'static str, diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 9f17332474d6aa861253ca7a24dda18b7fedb344..470ecce8b15122fb7ec57d1e9786d93c5c809320 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -173,7 +173,7 @@ fn main() { // }) // .detach(); - client.telemetry().start(installation_id, session_id, cx); + // client.telemetry().start(installation_id, session_id, cx); let app_state = Arc::new(AppState { languages, From 722ad5a01d4b838e688a214d27113437c487493e Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sun, 19 Nov 2023 22:03:55 -0500 Subject: [PATCH 4/6] Fix data types --- crates/zed/src/main.rs | 2 +- crates/zed2/src/main.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 0e7bd5c3c8abce5f8ff6ff553524cd83bd177432..a32c95d3e6d7d2887e4fd6b48688aaf51255c354 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -405,7 +405,7 @@ struct Panic { os_name: String, os_version: Option, architecture: String, - panicked_on: u128, + panicked_on: i64, #[serde(skip_serializing_if = "Option::is_none")] installation_id: Option, session_id: String, diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 470ecce8b15122fb7ec57d1e9786d93c5c809320..c32b335ca34b6b5ddb93d47a52235bc3229ce457 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -429,7 +429,7 @@ struct Panic { os_name: String, os_version: Option, architecture: String, - panicked_on: u128, + panicked_on: i64, #[serde(skip_serializing_if = "Option::is_none")] installation_id: Option, session_id: String, From 5dc3369cf6f350e11c9bee2e48a21d2fba20b0dd Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sun, 19 Nov 2023 22:04:02 -0500 Subject: [PATCH 5/6] Remove unused imports --- crates/zed/src/main.rs | 3 +-- crates/zed2/src/main.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index a32c95d3e6d7d2887e4fd6b48688aaf51255c354..5f2a7c525e0aea471583af9e361ad2063397d4fc 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result}; use backtrace::Backtrace; -use chrono::{DateTime, Utc}; +use chrono::Utc; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use client::{ self, Client, TelemetrySettings, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN, @@ -35,7 +35,6 @@ use std::{ Arc, Weak, }, thread, - time::{SystemTime, UNIX_EPOCH}, }; use util::{ channel::{parse_zed_link, ReleaseChannel}, diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index c32b335ca34b6b5ddb93d47a52235bc3229ce457..5d04e49216da609f0d529c6230c96c9c05b9b721 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -6,7 +6,7 @@ use anyhow::{anyhow, Context as _, Result}; use backtrace::Backtrace; -use chrono::{DateTime, Utc}; +use chrono::Utc; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use client::UserStore; use db::kvp::KEY_VALUE_STORE; @@ -39,7 +39,6 @@ use std::{ Arc, }, thread, - time::{SystemTime, UNIX_EPOCH}, }; use theme::ActiveTheme; use util::{ From 966bf56ddb681df2f16a1273e4badbc97233787d Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 20 Nov 2023 09:08:07 -0500 Subject: [PATCH 6/6] Activate telemetry in zed2 --- crates/zed2/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/zed2/src/main.rs b/crates/zed2/src/main.rs index 5d04e49216da609f0d529c6230c96c9c05b9b721..0532d62c386a57daf4ab23a674c3fd3780a0a921 100644 --- a/crates/zed2/src/main.rs +++ b/crates/zed2/src/main.rs @@ -172,7 +172,7 @@ fn main() { // }) // .detach(); - // client.telemetry().start(installation_id, session_id, cx); + client.telemetry().start(installation_id, session_id, cx); let app_state = Arc::new(AppState { languages,