From 93e1e303238d4c489e220b36d3fcd2111a2f5805 Mon Sep 17 00:00:00 2001 From: Joseph T Lyons Date: Thu, 27 Oct 2022 15:53:14 -0400 Subject: [PATCH] Add release channel information to telemetry events --- crates/auto_update/src/update_notification.rs | 6 +----- crates/client/src/amplitude_telemetry.rs | 6 ++++++ crates/client/src/telemetry.rs | 6 ++++++ crates/settings/src/settings.rs | 10 ++++++++++ crates/zed/src/main.rs | 6 +++--- crates/zed/src/zed.rs | 6 +----- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/crates/auto_update/src/update_notification.rs b/crates/auto_update/src/update_notification.rs index 19faca24a0..13e5f0517d 100644 --- a/crates/auto_update/src/update_notification.rs +++ b/crates/auto_update/src/update_notification.rs @@ -29,11 +29,7 @@ impl View for UpdateNotification { let theme = cx.global::().theme.clone(); let theme = &theme.update_notification; - let app_name = match *cx.global::() { - ReleaseChannel::Dev => "Zed Dev", - ReleaseChannel::Preview => "Zed Preview", - ReleaseChannel::Stable => "Zed", - }; + let app_name = cx.global::().name(); MouseEventHandler::::new(0, cx, |state, cx| { Flex::column() diff --git a/crates/client/src/amplitude_telemetry.rs b/crates/client/src/amplitude_telemetry.rs index ef0ec2e209..38a916e9e0 100644 --- a/crates/client/src/amplitude_telemetry.rs +++ b/crates/client/src/amplitude_telemetry.rs @@ -10,6 +10,7 @@ use lazy_static::lazy_static; use parking_lot::Mutex; use serde::Serialize; use serde_json::json; +use settings::ReleaseChannel; use std::{ io::Write, mem, @@ -33,6 +34,7 @@ struct AmplitudeTelemetryState { metrics_id: Option>, device_id: Option>, app_version: Option>, + release_channel: &'static str, os_version: Option>, os_name: &'static str, queue: Vec, @@ -70,6 +72,7 @@ struct AmplitudeEvent { app_version: Option>, #[serde(rename = "App")] app: &'static str, + release_channel: &'static str, event_id: usize, session_id: u128, time: u128, @@ -90,6 +93,7 @@ const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl AmplitudeTelemetry { pub fn new(client: Arc, cx: &AppContext) -> Arc { let platform = cx.platform(); + let release_channel = cx.global::().name(); let this = Arc::new(Self { http_client: client, executor: cx.background().clone(), @@ -107,6 +111,7 @@ impl AmplitudeTelemetry { .app_version() .log_err() .map(|v| v.to_string().into()), + release_channel, device_id: None, queue: Default::default(), flush_task: Default::default(), @@ -221,6 +226,7 @@ impl AmplitudeTelemetry { app: "Zed", os_version: state.os_version.clone(), app_version: state.app_version.clone(), + release_channel: state.release_channel, event_id: post_inc(&mut state.next_event_id), }; state.queue.push(event); diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index 850001f6d8..01eca61c0a 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -10,6 +10,7 @@ use lazy_static::lazy_static; use parking_lot::Mutex; use serde::Serialize; use serde_json::json; +use settings::ReleaseChannel; use std::{ io::Write, mem, @@ -32,6 +33,7 @@ struct TelemetryState { metrics_id: Option>, device_id: Option>, app_version: Option>, + release_channel: &'static str, os_version: Option>, os_name: &'static str, queue: Vec, @@ -69,6 +71,7 @@ struct MixpanelEventProperties { event_properties: Option>, os_name: &'static str, os_version: Option>, + release_channel: &'static str, app_version: Option>, signed_in: bool, #[serde(rename = "App")] @@ -100,6 +103,7 @@ const DEBOUNCE_INTERVAL: Duration = Duration::from_secs(30); impl Telemetry { pub fn new(client: Arc, cx: &AppContext) -> Arc { let platform = cx.platform(); + let release_channel = cx.global::().name(); let this = Arc::new(Self { http_client: client, executor: cx.background().clone(), @@ -113,6 +117,7 @@ impl Telemetry { .app_version() .log_err() .map(|v| v.to_string().into()), + release_channel, device_id: None, metrics_id: None, queue: Default::default(), @@ -228,6 +233,7 @@ impl Telemetry { }, os_name: state.os_name, os_version: state.os_version.clone(), + release_channel: state.release_channel, app_version: state.app_version.clone(), signed_in: state.metrics_id.is_some(), app: "Zed", diff --git a/crates/settings/src/settings.rs b/crates/settings/src/settings.rs index bad35c3271..e801e00757 100644 --- a/crates/settings/src/settings.rs +++ b/crates/settings/src/settings.rs @@ -62,6 +62,16 @@ pub enum ReleaseChannel { Stable, } +impl ReleaseChannel { + pub fn name(&self) -> &'static str { + match self { + ReleaseChannel::Dev => "Zed Dev", + ReleaseChannel::Preview => "Zed Preview", + ReleaseChannel::Stable => "Zed", + } + } +} + impl FeatureFlags { pub fn keymap_files(&self) -> Vec<&'static str> { vec![] diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 9d0f8b33e8..04e93e8dd9 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -86,6 +86,9 @@ fn main() { }); app.run(move |cx| { + cx.set_global(*RELEASE_CHANNEL); + cx.set_global(HomeDir(zed::paths::HOME.to_path_buf())); + let client = client::Client::new(http.clone(), cx); let mut languages = LanguageRegistry::new(login_shell_env_loaded); languages.set_language_server_download_dir(zed::paths::LANGUAGES_DIR.clone()); @@ -97,9 +100,6 @@ fn main() { let (settings_file_content, keymap_file) = cx.background().block(config_files).unwrap(); - cx.set_global(*RELEASE_CHANNEL); - cx.set_global(HomeDir(zed::paths::HOME.to_path_buf())); - //Setup settings global before binding actions cx.set_global(SettingsFile::new( &*zed::paths::SETTINGS, diff --git a/crates/zed/src/zed.rs b/crates/zed/src/zed.rs index 6536d83ce6..67407ba9b8 100644 --- a/crates/zed/src/zed.rs +++ b/crates/zed/src/zed.rs @@ -389,11 +389,7 @@ fn quit(_: &Quit, cx: &mut gpui::MutableAppContext) { } fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext) { - let app_name = match *cx.global::() { - ReleaseChannel::Dev => "Zed Dev", - ReleaseChannel::Preview => "Zed Preview", - ReleaseChannel::Stable => "Zed", - }; + let app_name = cx.global::().name(); let version = env!("CARGO_PKG_VERSION"); cx.prompt( gpui::PromptLevel::Info,