From bf4331e8cf9c5954069acce52ba32b8d16550085 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 31 Oct 2022 16:42:28 -0400 Subject: [PATCH] Merge pull request #1829 from zed-industries/add-release-channel-information-to-telemetry-events Add release channel information to telemetry events --- crates/auto_update/src/update_notification.rs | 6 +----- crates/client/src/telemetry.rs | 17 ++++++++++++++++- crates/editor/src/editor.rs | 2 +- crates/settings/src/settings.rs | 10 ++++++++++ crates/zed/src/main.rs | 6 +++--- crates/zed/src/zed.rs | 6 +----- 6 files changed, 32 insertions(+), 15 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/telemetry.rs b/crates/client/src/telemetry.rs index d2ead6b341..c791b0e719 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: Option<&'static str>, os_version: Option>, os_name: &'static str, queue: Vec, @@ -67,9 +69,15 @@ struct MixpanelEventProperties { // Custom fields #[serde(skip_serializing_if = "Option::is_none", flatten)] event_properties: Option>, + #[serde(rename = "OS Name")] os_name: &'static str, + #[serde(rename = "OS Version")] os_version: Option>, + #[serde(rename = "Release Channel")] + release_channel: Option<&'static str>, + #[serde(rename = "App Version")] app_version: Option>, + #[serde(rename = "Signed In")] signed_in: bool, platform: &'static str, } @@ -99,6 +107,11 @@ 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 = if cx.has_global::() { + Some(cx.global::().name()) + } else { + None + }; let this = Arc::new(Self { http_client: client, executor: cx.background().clone(), @@ -106,6 +119,7 @@ impl Telemetry { os_version: platform.os_version().ok().map(|v| v.to_string().into()), os_name: platform.os_name().into(), app_version: platform.app_version().ok().map(|v| v.to_string().into()), + release_channel, device_id: None, metrics_id: None, queue: Default::default(), @@ -188,7 +202,7 @@ impl Telemetry { let json_bytes = serde_json::to_vec(&[MixpanelEngageRequest { token, distinct_id: device_id, - set: json!({ "staff": is_staff, "id": metrics_id }), + set: json!({ "Staff": is_staff, "ID": metrics_id }), }])?; let request = Request::post(MIXPANEL_ENGAGE_URL) .header("Content-Type", "application/json") @@ -221,6 +235,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(), platform: "Zed", diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 327f143db5..cb6b569223 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -6396,7 +6396,7 @@ impl Editor { project.read(cx).client().report_event( name, json!({ - "file_extension": file + "File Extension": file .path() .extension() .and_then(|e| e.to_str()) 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 c515d89a28..74a38599ec 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -90,6 +90,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()); @@ -101,9 +104,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 0d497afd52..f54114891c 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,