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
This commit is contained in:
Anthony Eid
2026-11-10 09:43:33 +00:00
committed by GitHub
parent bfcd5949ff
commit 0929d569fa
7 changed files with 88 additions and 14 deletions
+37 -3
View File
@@ -62,6 +62,7 @@ struct TelemetryState {
worktrees_with_project_type_events_sent: HashSet<WorktreeId>,
os_name: String,
desktop_environment: Option<String>,
app_version: String,
os_version: Option<String>,
@@ -106,7 +107,36 @@ static DOTNET_PROJECT_FILES_REGEX: LazyLock<Regex> = 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<Self>) -> 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(),
+6
View File
@@ -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(),
+6 -6
View File
@@ -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| {
+30 -2
View File
@@ -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<OsString>,
/// `XDG_RUNTIME_DIR`: the directory containing Wayland sockets.
pub xdg_runtime_dir: Option<OsString>,
/// `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<OsString>,
/// `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<String> {
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<String> {
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<String> {
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"
}
}
}
@@ -21,6 +21,9 @@ pub struct EventRequestBody {
pub app_version: String,
pub os_name: String,
pub os_version: Option<String>,
/// The Linux or FreeBSD desktop environment, from `XDG_CURRENT_DESKTOP`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub desktop_environment: Option<String>,
pub architecture: String,
/// Zed release channel (stable, preview, dev)
pub release_channel: Option<String>,
+1 -1
View File
@@ -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);
+5 -2
View File
@@ -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() })