From 0929d569fa3e1b1968b7c486f09c599fe1334587 Mon Sep 17 00:00:00 2001 From: Anthony Eid <56899983+Anthony-Eid@users.noreply.github.com> Date: Tue, 10 Nov 2026 09:43:33 +0000 Subject: [PATCH] client: Report Linux desktop environment and connected display server in telemetry (#66772) Telemetry now reports the display server Zed actually connected to instead of guessing from environment variables, so `os_name` is correct when Wayland falls back to X11. It also sends the connected session's desktop environment (`XDG_CURRENT_DESKTOP`), so we can split Linux hang and frame data by desktop. Release Notes: - [GPUI] Added `GraphicalEnvironment::desktop_environment()` for reading the connected session's desktop environment - N/A --- crates/client/src/telemetry.rs | 40 +++++++++++++++++-- crates/collab/src/api/events.rs | 6 +++ crates/feedback/src/feedback.rs | 12 +++--- crates/gpui/src/platform.rs | 32 ++++++++++++++- .../telemetry_events/src/telemetry_events.rs | 3 ++ crates/zed/src/main.rs | 2 +- crates/zed/src/watcher_debug.rs | 7 +++- 7 files changed, 88 insertions(+), 14 deletions(-) diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rs index a08dfb44bd6..72426132a1c 100644 --- a/crates/client/src/telemetry.rs +++ b/crates/client/src/telemetry.rs @@ -62,6 +62,7 @@ struct TelemetryState { worktrees_with_project_type_events_sent: HashSet, os_name: String, + desktop_environment: Option, app_version: String, os_version: Option, @@ -106,7 +107,36 @@ static DOTNET_PROJECT_FILES_REGEX: LazyLock = LazyLock::new(|| { Regex::new(r"^(global\.json|Directory\.Build\.props|.*\.(csproj|fsproj|vbproj|sln))$").unwrap() }); -pub fn os_name() -> String { +/// Returns the OS name, including the display server the platform connected to. +#[cfg_attr( + not(any(target_os = "linux", target_os = "freebsd")), + expect(unused_variables) +)] +pub fn os_name(cx: &App) -> String { + #[cfg(target_os = "macos")] + { + "macOS".to_string() + } + #[cfg(target_os = "linux")] + { + format!("Linux {}", cx.compositor_name()) + } + #[cfg(target_os = "freebsd")] + { + format!("FreeBSD {}", cx.compositor_name()) + } + + #[cfg(target_os = "windows")] + { + "Windows".to_string() + } +} + +/// Returns the OS name, guessing the display server from the environment. +/// +/// Prefer [`os_name`] once an [`App`] exists; the platform may connect to a +/// different display server than the environment suggests. +pub fn guessed_os_name() -> String { #[cfg(target_os = "macos")] { "macOS".to_string() @@ -206,7 +236,10 @@ impl Telemetry { worktrees_with_project_type_events_sent: HashSet::new(), os_version: None, - os_name: os_name(), + os_name: os_name(cx), + desktop_environment: cx + .graphical_environment() + .and_then(|environment| environment.desktop_environment()), app_version: release_channel::AppVersion::global(cx).to_string(), subscribers: Vec::new(), })); @@ -365,7 +398,7 @@ impl Telemetry { state.installation_id = installation_id.map(|id| id.into()); state.session_id = Some(session_id); state.app_version = release_channel::AppVersion::global(cx).to_string(); - state.os_name = os_name(); + state.os_name = os_name(cx); } pub fn metrics_enabled(self: &Arc) -> bool { @@ -688,6 +721,7 @@ impl Telemetry { is_staff: state.is_staff, app_version: state.app_version.clone(), os_name: state.os_name.clone(), + desktop_environment: state.desktop_environment.clone(), os_version: state.os_version.clone(), architecture: state.architecture.to_string(), diff --git a/crates/collab/src/api/events.rs b/crates/collab/src/api/events.rs index 0c1419144d4..bfcb8a3ad51 100644 --- a/crates/collab/src/api/events.rs +++ b/crates/collab/src/api/events.rs @@ -148,6 +148,12 @@ fn for_snowflake( map.insert("app_version".to_string(), body.app_version.clone().into()); map.insert("os_name".to_string(), body.os_name.clone().into()); map.insert("os_version".to_string(), body.os_version.clone().into()); + if let Some(desktop_environment) = body.desktop_environment.as_ref() { + map.insert( + "desktop_environment".to_string(), + desktop_environment.clone().into(), + ); + } map.insert("architecture".to_string(), body.architecture.clone().into()); map.insert( "release_channel".to_string(), diff --git a/crates/feedback/src/feedback.rs b/crates/feedback/src/feedback.rs index 16c91ce769d..6fb59d9874d 100644 --- a/crates/feedback/src/feedback.rs +++ b/crates/feedback/src/feedback.rs @@ -49,8 +49,8 @@ pub fn init(cx: &mut App) { cx.observe_new(|workspace: &mut Workspace, _, _| { workspace .register_action(|_, _: &CopySystemSpecsIntoClipboard, window, cx| { - let specs = - SystemSpecs::new(window, cx, telemetry::os_name(), telemetry::os_version()); + let os_name = telemetry::os_name(cx); + let specs = SystemSpecs::new(window, cx, os_name, telemetry::os_version()); cx.spawn_in(window, async move |_, cx| { let specs = specs.await.to_string(); @@ -85,8 +85,8 @@ pub fn init(cx: &mut App) { cx.open_url(REQUEST_FEATURE_URL); }) .register_action(move |_, _: &FileBugReport, window, cx| { - let specs = - SystemSpecs::new(window, cx, telemetry::os_name(), telemetry::os_version()); + let os_name = telemetry::os_name(cx); + let specs = SystemSpecs::new(window, cx, os_name, telemetry::os_version()); cx.spawn_in(window, async move |_, cx| { let specs = specs.await; cx.update(|_, cx| { @@ -97,8 +97,8 @@ pub fn init(cx: &mut App) { .detach(); }) .register_action(move |_, _: &EmailZed, window, cx| { - let specs = - SystemSpecs::new(window, cx, telemetry::os_name(), telemetry::os_version()); + let os_name = telemetry::os_name(cx); + let specs = SystemSpecs::new(window, cx, os_name, telemetry::os_version()); cx.spawn_in(window, async move |_, cx| { let specs = specs.await; cx.update(|_, cx| { diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index b84bcc5c092..8f44cc02308 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -209,7 +209,7 @@ impl ActivityGuard { #[inline] pub fn guess_compositor() -> &'static str { if std::env::var_os("ZED_HEADLESS").is_some() { - return "Headless"; + return "headless"; } GraphicalEnvironment::detect().guess_compositor() } @@ -231,6 +231,11 @@ pub struct GraphicalEnvironment { pub x11_display: Option, /// `XDG_RUNTIME_DIR`: the directory containing Wayland sockets. pub xdg_runtime_dir: Option, + /// `XDG_CURRENT_DESKTOP`: the session's desktop environment, such as `ubuntu:GNOME`. + /// + /// Only reported by [`GraphicalEnvironment::desktop_environment`]; [`GraphicalEnvironment::apply_to`] + /// leaves it alone. + pub current_desktop: Option, /// `XDG_ACTIVATION_TOKEN`: lets the first window take focus on Wayland. /// /// A platform takes this process's token from its environment when it's created, and uses @@ -272,6 +277,11 @@ impl GraphicalEnvironment { /// Does nothing on this platform: programs inherit the session of the process that /// starts them. pub fn apply_to(&self, _command: &mut std::process::Command) {} + + /// Returns `None`: this platform has no desktop environments to tell apart. + pub fn desktop_environment(&self) -> Option { + None + } } /// The graphical session to connect to. Carries nothing yet on this platform. @@ -288,6 +298,11 @@ impl GraphicalEnvironment { /// Does nothing on this platform. pub fn apply_to(&self, _command: &mut std::process::Command) {} + + /// Returns `None`: this platform has no desktop environments to tell apart. + pub fn desktop_environment(&self) -> Option { + None + } } /// A display mode for [`App::request_windowing`] to switch to. @@ -310,6 +325,7 @@ impl GraphicalEnvironment { wayland_display: std::env::var_os("WAYLAND_DISPLAY"), x11_display: std::env::var_os("DISPLAY"), xdg_runtime_dir: std::env::var_os("XDG_RUNTIME_DIR"), + current_desktop: std::env::var_os("XDG_CURRENT_DESKTOP"), activation_token: None, } } @@ -330,6 +346,18 @@ impl GraphicalEnvironment { } } + /// Returns the session's desktop environment, if `XDG_CURRENT_DESKTOP` names one. + /// + /// The value is a colon-separated list ordered from most to least specific, + /// such as `ubuntu:GNOME`. + pub fn desktop_environment(&self) -> Option { + self.current_desktop + .as_ref() + .and_then(|desktop| desktop.to_str()) + .filter(|desktop| !desktop.is_empty()) + .map(str::to_owned) + } + /// Returns the compositor this environment selects: Wayland, then X11, then headless. /// /// Does not attempt to connect to the compositor. @@ -341,7 +369,7 @@ impl GraphicalEnvironment { } else if cfg!(feature = "x11") && is_set(&self.x11_display) { "X11" } else { - "Headless" + "headless" } } } diff --git a/crates/telemetry_events/src/telemetry_events.rs b/crates/telemetry_events/src/telemetry_events.rs index e98a2c025fd..de1af3f7f5a 100644 --- a/crates/telemetry_events/src/telemetry_events.rs +++ b/crates/telemetry_events/src/telemetry_events.rs @@ -21,6 +21,9 @@ pub struct EventRequestBody { pub app_version: String, pub os_name: String, pub os_version: Option, + /// The Linux or FreeBSD desktop environment, from `XDG_CURRENT_DESKTOP`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub desktop_environment: Option, pub architecture: String, /// Zed release channel (stable, preview, dev) pub release_channel: Option, diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 9d4a63a3958..4057dd7a0db 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -312,7 +312,7 @@ fn main() { app_version, app_commit_sha, *release_channel::RELEASE_CHANNEL, - client::telemetry::os_name(), + client::telemetry::guessed_os_name(), client::telemetry::os_version(), ); println!("Zed System Specs (from CLI):\n{}", system_specs); diff --git a/crates/zed/src/watcher_debug.rs b/crates/zed/src/watcher_debug.rs index 4d432ea51d4..bbafd1f0919 100644 --- a/crates/zed/src/watcher_debug.rs +++ b/crates/zed/src/watcher_debug.rs @@ -401,7 +401,7 @@ impl WatcherDebug { let watcher = recording.snapshot(); let worktree_scan_exclusions = worktree_exclusions(&self.app_state, cx); let zed_version = AppVersion::global(cx).to_string(); - let os_name = client::telemetry::os_name(); + let os_name = client::telemetry::os_name(cx); let directory = std::env::home_dir().unwrap_or_default(); let path = cx.prompt_for_new_path(&directory, Some("filesystem-watcher.json")); let fs = self.app_state.fs.clone(); @@ -889,7 +889,10 @@ mod tests { cx.run_until_parked(); let json: serde_json::Value = serde_json::from_str(&fs.load(&path).await.unwrap()).unwrap(); assert_eq!(json["zed_version"], "1.2.3+dev.test"); - assert_eq!(json["os_name"], client::telemetry::os_name()); + assert_eq!( + json["os_name"], + cx.update(|cx| client::telemetry::os_name(cx)) + ); let os_version = cx .background_executor .spawn(async { client::telemetry::os_version() })