From 2c7e37e9fff48031618f956374848c952a7364a5 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 6 Oct 2023 12:32:20 -0400 Subject: [PATCH] Add session id to panic events --- crates/client/src/telemetry.rs | 45 ++++++++++++++++++---------------- crates/zed/src/main.rs | 9 ++++--- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 0f753679e1..70878bf2e4 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -8,7 +8,6 @@ use sysinfo::{Pid, PidExt, ProcessExt, System, SystemExt}; use tempfile::NamedTempFile; use util::http::HttpClient; use util::{channel::ReleaseChannel, TryFutureExt}; -use uuid::Uuid; pub struct Telemetry { http_client: Arc, @@ -20,7 +19,7 @@ pub struct Telemetry { struct TelemetryState { metrics_id: Option>, // Per logged-in user installation_id: Option>, // Per app installation (different for dev, preview, and stable) - session_id: String, // Per app launch + session_id: Option>, // Per app launch app_version: Option>, release_channel: Option<&'static str>, os_name: &'static str, @@ -43,7 +42,7 @@ lazy_static! { struct ClickhouseEventRequestBody { token: &'static str, installation_id: Option>, - session_id: String, + session_id: Option>, is_staff: Option, app_version: Option>, os_name: &'static str, @@ -134,7 +133,7 @@ impl Telemetry { release_channel, installation_id: None, metrics_id: None, - session_id: Uuid::new_v4().to_string(), + session_id: None, clickhouse_events_queue: Default::default(), flush_clickhouse_events_task: Default::default(), log_file: None, @@ -149,9 +148,15 @@ impl Telemetry { Some(self.state.lock().log_file.as_ref()?.path().to_path_buf()) } - pub fn start(self: &Arc, installation_id: Option, cx: &mut AppContext) { + pub fn start( + self: &Arc, + installation_id: Option, + session_id: String, + cx: &mut AppContext, + ) { let mut state = self.state.lock(); state.installation_id = installation_id.map(|id| id.into()); + state.session_id = Some(session_id.into()); let has_clickhouse_events = !state.clickhouse_events_queue.is_empty(); drop(state); @@ -283,23 +288,21 @@ impl Telemetry { { let state = this.state.lock(); - json_bytes.clear(); - serde_json::to_writer( - &mut json_bytes, - &ClickhouseEventRequestBody { - token: ZED_SECRET_CLIENT_TOKEN, - installation_id: state.installation_id.clone(), - session_id: state.session_id.clone(), - is_staff: state.is_staff.clone(), - app_version: state.app_version.clone(), - os_name: state.os_name, - os_version: state.os_version.clone(), - architecture: state.architecture, + let request_body = ClickhouseEventRequestBody { + token: ZED_SECRET_CLIENT_TOKEN, + installation_id: state.installation_id.clone(), + session_id: state.session_id.clone(), + is_staff: state.is_staff.clone(), + app_version: state.app_version.clone(), + os_name: state.os_name, + os_version: state.os_version.clone(), + architecture: state.architecture, - release_channel: state.release_channel, - events, - }, - )?; + release_channel: state.release_channel, + events, + }; + json_bytes.clear(); + serde_json::to_writer(&mut json_bytes, &request_body)?; } this.http_client diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index d6f3be2b46..704eef464c 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -74,7 +74,8 @@ fn main() { let mut app = gpui::App::new(Assets).unwrap(); let installation_id = app.background().block(installation_id()).ok(); - init_panic_hook(&app, installation_id.clone()); + let session_id = Uuid::new_v4().to_string(); + init_panic_hook(&app, installation_id.clone(), session_id.clone()); load_embedded_fonts(&app); @@ -177,7 +178,7 @@ fn main() { }) .detach(); - client.telemetry().start(installation_id, cx); + client.telemetry().start(installation_id, session_id, cx); let app_state = Arc::new(AppState { languages, @@ -402,6 +403,7 @@ struct Panic { panicked_on: u128, #[serde(skip_serializing_if = "Option::is_none")] installation_id: Option, + session_id: String, } #[derive(Serialize)] @@ -412,7 +414,7 @@ struct PanicRequest { static PANIC_COUNT: AtomicU32 = AtomicU32::new(0); -fn init_panic_hook(app: &App, installation_id: Option) { +fn init_panic_hook(app: &App, installation_id: Option, session_id: String) { let is_pty = stdout_is_a_pty(); let platform = app.platform(); @@ -490,6 +492,7 @@ fn init_panic_hook(app: &App, installation_id: Option) { .as_millis(), backtrace, installation_id: installation_id.clone(), + session_id: session_id.clone(), }; if is_pty {