Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

feat(telemetry): ui_locale on cua_app_active (CUA-1928) (#5569)

Francesco Bonaccie4b0baaf5f3c
diff --git a/apps/cua-spaces/src-tauri/src/lib.rs b/apps/cua-spaces/src-tauri/src/lib.rs
index 50c4cc15c4..7803b60152 100644
--- a/apps/cua-spaces/src-tauri/src/lib.rs
+++ b/apps/cua-spaces/src-tauri/src/lib.rs
@@ -578,6 +578,7 @@ pub fn run() {
telemetry::telemetry_record_feature,
telemetry::telemetry_record_step,
telemetry::telemetry_record_signals,
+ telemetry::telemetry_set_ui_locale,
telemetry::telemetry_welcome_left,
telemetry::telemetry_record_stream,
webview_data::ui_storage_set,
diff --git a/apps/cua-spaces/src-tauri/src/telemetry.rs b/apps/cua-spaces/src-tauri/src/telemetry.rs
index 4f713bea2e..12209f11af 100644
--- a/apps/cua-spaces/src-tauri/src/telemetry.rs
+++ b/apps/cua-spaces/src-tauri/src/telemetry.rs
@@ -253,6 +253,15 @@ pub fn telemetry_record_signals(signals: Vec<TelemetrySignal>) {
record(&signals);
}
+/// The app's interface language (`ui_locale` on the day's `cua_app_active`):
+/// one of a fixed set, anything else is `other`. Nothing when telemetry is off.
+#[tauri::command]
+pub fn telemetry_set_ui_locale(locale: String) {
+ if let Some(t) = t() {
+ t.set_ui_locale(&locale);
+ }
+}
+
/// A feature used in the webview (fixed names only).
#[tauri::command]
pub fn telemetry_record_feature(feature_name: String) {
diff --git a/apps/cua-spaces/src/components/InstallerFlow.test.tsx b/apps/cua-spaces/src/components/InstallerFlow.test.tsx
index a4bb6941dd..c733e272ea 100644
--- a/apps/cua-spaces/src/components/InstallerFlow.test.tsx
+++ b/apps/cua-spaces/src/components/InstallerFlow.test.tsx
@@ -62,6 +62,7 @@ function fakeTelemetry() {
view.enabled = on;
return view;
},
+ setUiLocale: () => {},
recordFeature: () => {},
recordStep: () => {},
recordStream: () => {},
diff --git a/apps/cua-spaces/src/components/SettingsPanel.test.tsx b/apps/cua-spaces/src/components/SettingsPanel.test.tsx
index b9fed6b1bf..a18e75a5b2 100644
--- a/apps/cua-spaces/src/components/SettingsPanel.test.tsx
+++ b/apps/cua-spaces/src/components/SettingsPanel.test.tsx
@@ -365,6 +365,7 @@ describe("SettingsPanel Privacy", () => {
view = { ...view, enabled, source: "config /tmp/cua/config.toml", sourceKind: "config" };
return view;
},
+ setUiLocale: () => {},
recordFeature: () => {},
recordStep: () => {},
recordStream: () => {},
@@ -420,6 +421,7 @@ describe("SettingsPanel Experiments", () => {
acknowledgeNotice: async () => view,
setEnabled: async () => view,
welcomeLeft: async () => view,
+ setUiLocale: () => {},
recordFeature: () => {},
recordStep: () => {},
recordStream: () => {},
diff --git a/apps/cua-spaces/src/native/telemetry.ts b/apps/cua-spaces/src/native/telemetry.ts
index 8ce3621874..7fddd001d1 100644
--- a/apps/cua-spaces/src/native/telemetry.ts
+++ b/apps/cua-spaces/src/native/telemetry.ts
@@ -34,6 +34,11 @@ export interface TelemetryBridge {
* shown. Nothing is sent before; with it off, nothing after either.
*/
welcomeLeft(on: boolean): Promise<TelemetryView>;
+ /**
+ * The interface language (`en`, `zh-Hans`, `ko`, `pt-BR`, `ja`, `es`); the
+ * shell maps anything else to `other`. Kept for the day's `cua_app_active`.
+ */
+ setUiLocale(locale: string): void;
/** A fixed feature name (see the docs); anything else is dropped. */
recordFeature(feature: string): void;
/** A fixed funnel step name; anything else is dropped. */
@@ -62,6 +67,9 @@ export function createTauriTelemetryBridge(): TelemetryBridge {
setEnabled: (enabled) => invoke<TelemetryView>("telemetry_set_enabled", { enabled }),
acknowledgeNotice: () => invoke<TelemetryView>("telemetry_acknowledge_notice"),
welcomeLeft: (on) => invoke<TelemetryView>("telemetry_welcome_left", { on }),
+ setUiLocale: (locale) => {
+ void invoke<void>("telemetry_set_ui_locale", { locale }).catch(() => {});
+ },
recordFeature: (feature) => {
void invoke<void>("telemetry_record_feature", { featureName: feature }).catch(() => {});
},
@@ -99,6 +107,7 @@ export function createFallbackTelemetryBridge(): TelemetryBridge {
setEnabled: async () => off(),
acknowledgeNotice: async () => off(),
welcomeLeft: async () => off(),
+ setUiLocale: () => {},
recordFeature: () => {},
recordStep: () => {},
recordStream: () => {},
diff --git a/apps/cua-spaces/src/viewer/MediaCanvas.telemetry.test.tsx b/apps/cua-spaces/src/viewer/MediaCanvas.telemetry.test.tsx
index 3f86a58213..d9bf7407d6 100644
--- a/apps/cua-spaces/src/viewer/MediaCanvas.telemetry.test.tsx
+++ b/apps/cua-spaces/src/viewer/MediaCanvas.telemetry.test.tsx
@@ -30,6 +30,7 @@ function bridge() {
status: vi.fn(),
setEnabled: vi.fn(),
acknowledgeNotice: vi.fn(),
+ setUiLocale: vi.fn(),
recordFeature: vi.fn(),
recordStep: vi.fn(),
recordStream,
diff --git a/docs/content/docs/cua-sdk/concepts/telemetry-events.mdx b/docs/content/docs/cua-sdk/concepts/telemetry-events.mdx
index b66042eb07..e50f30adc1 100644
--- a/docs/content/docs/cua-sdk/concepts/telemetry-events.mdx
+++ b/docs/content/docs/cua-sdk/concepts/telemetry-events.mdx
@@ -36,7 +36,7 @@ Every event carries: `telemetry_schema_version`, `event_version`, `product`
| `cua_daemon_health` | `uptime_bucket`, `sandboxes` | Hourly aggregate health. |
| `cua_spacesd_health` | `uptime_bucket`, `imports_failed` | In-sandbox health, hourly. |
| `cua_spacesd_session_deliveries` | `delivery_grant` (`present` or `absent`), `count` | Session deliveries with and without a Keyvault grant. |
-| `cua_app_active` | `experiments_on` (the Cua Spaces experiments turned on in Settings, Experiments: `cua_volume`, `your_cloud`, `sharing` joined with `+`, or `none`) | Daily and weekly active installs and retention: at most one per install per UTC day. Also installs per experiment. |
+| `cua_app_active` | `experiments_on` (the Cua Spaces experiments turned on in Settings, Experiments: `cua_volume`, `your_cloud`, `sharing` joined with `+`, or `none`), `ui_locale` (the Cua Spaces interface language: `en`, `zh-Hans`, `ko`, `pt-BR`, `ja`, `es`, or `other`; never a region or free text) | Daily and weekly active installs and retention: at most one per install per UTC day. Also installs per experiment, and which languages to ship. |
| `cua_onboarding_page` | `page` (`welcome`, `command_line`, `signin`, `agents`, `presentation`, `volume`, `this_machine`, `done`), `action` (`shown`, `completed`, `skipped`, `back`), `choice` (a fixed word such as `installed`, `signed_in`, `menu_bar_only`, `s3`, `host`, or `none`) | Which first-run page people leave on, and what they pick. |
| `cua_space_wizard` | `action` (`opened`, `cancelled`, `submitted`) | How often a New Space is started and abandoned. |
| `cua_space_create_started` | `location`, `guest_os`, `kind`, `gpu` (GPU acceleration turned on) | Which Spaces are started, and how often with GPU acceleration. |
diff --git a/libs/cua/crates/cua-telemetry/src/client.rs b/libs/cua/crates/cua-telemetry/src/client.rs
index d800c5d48f..9078bc236f 100644
--- a/libs/cua/crates/cua-telemetry/src/client.rs
+++ b/libs/cua/crates/cua-telemetry/src/client.rs
@@ -49,6 +49,8 @@ const ACTIVE_DAY_FILE: &str = "active_day";
const AGENT_USED_SPACE_FILE: &str = "agent_used_space_day";
/// The Spaces app's experiments that are on (`cua_volume+sharing`, `none`).
const EXPERIMENTS_FILE: &str = "experiments_on";
+/// The Spaces app's interface language (`en`, `zh-Hans`, ..., `other`).
+const UI_LOCALE_FILE: &str = "ui_locale";
/// What happened to one captured event.
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -850,7 +852,14 @@ impl Telemetry {
// this install sends the day's event; the set is the install's).
let experiments = std::fs::read_to_string(dir.join(EXPERIMENTS_FILE)).unwrap_or_default();
let ids: Vec<&str> = experiments.trim().split('+').collect();
- let r = self.capture(crate::events::app_active_with(&ids));
+ // And the interface language it last said (`en` before it says).
+ let locale = std::fs::read_to_string(dir.join(UI_LOCALE_FILE)).unwrap_or_default();
+ let locale = if locale.trim().is_empty() {
+ "en"
+ } else {
+ locale.trim()
+ };
+ let r = self.capture(crate::events::app_active_with(&ids, locale));
if r == Captured::Queued {
let _ = fsutil::write_replace(&marker, today.as_bytes());
}
@@ -914,6 +923,23 @@ impl Telemetry {
let _ = fsutil::write_replace(&path, format!("{word}\n").as_bytes());
}
+ /// The Spaces app's interface language now (a fixed set; any other
+ /// language is `other`): kept in the state directory, so the day's
+ /// `cua_app_active` carries it whichever product sends it. Nothing is
+ /// written while telemetry is off.
+ pub fn set_ui_locale(&self, locale: &str) {
+ if !self.is_enabled() {
+ return;
+ }
+ let Some(dir) = self.state_dir() else { return };
+ let path = dir.join(UI_LOCALE_FILE);
+ let word = crate::events::ui_locale(locale);
+ if std::fs::read_to_string(&path).is_ok_and(|s| s.trim() == word) {
+ return;
+ }
+ let _ = fsutil::write_replace(&path, format!("{word}\n").as_bytes());
+ }
+
fn log_last(&self, payload: &Value, status: &str) {
let Some(dir) = self.state_dir() else { return };
let path = dir.join(LAST_FILE);
diff --git a/libs/cua/crates/cua-telemetry/src/events.rs b/libs/cua/crates/cua-telemetry/src/events.rs
index 71debfd068..5860fc2859 100644
--- a/libs/cua/crates/cua-telemetry/src/events.rs
+++ b/libs/cua/crates/cua-telemetry/src/events.rs
@@ -853,13 +853,27 @@ pub fn create_time_bucket(d: Duration) -> &'static str {
/// `cua_app_active` (send it with `Telemetry::capture_active_day`, which
/// keeps it to one per install per UTC day), with no experiment on.
pub fn app_active() -> Event {
- app_active_with(&[])
+ app_active_with(&[], "en")
}
/// `cua_app_active` with the Spaces app's experiments that are on
-/// (`experiments_on`, [`experiments_set`]).
-pub fn app_active_with(experiments: &[&str]) -> Event {
- Event::new(event::APP_ACTIVE).owned("experiments_on", experiments_set(experiments))
+/// (`experiments_on`, [`experiments_set`]) and its interface language
+/// (`ui_locale`, [`ui_locale`]).
+pub fn app_active_with(experiments: &[&str], locale: &str) -> Event {
+ Event::new(event::APP_ACTIVE)
+ .owned("experiments_on", experiments_set(experiments))
+ .s("ui_locale", ui_locale(locale))
+}
+
+/// The interface language in [`schema::UI_LOCALES`] (matched exactly after
+/// trimming); anything else, including an empty value, is `other`.
+pub fn ui_locale(locale: &str) -> &'static str {
+ let l = locale.trim();
+ schema::UI_LOCALES
+ .iter()
+ .copied()
+ .find(|k| *k == l && *k != "other")
+ .unwrap_or("other")
}
/// The experiments in `ids` that are in [`schema::EXPERIMENTS`], in its
diff --git a/libs/cua/crates/cua-telemetry/src/schema.rs b/libs/cua/crates/cua-telemetry/src/schema.rs
index c3893b7c5e..4de722abce 100644
--- a/libs/cua/crates/cua-telemetry/src/schema.rs
+++ b/libs/cua/crates/cua-telemetry/src/schema.rs
@@ -515,6 +515,9 @@ pub const ENROLL_METHODS: &[&str] = &["sign_in", "approval", "rekey"];
/// The Spaces app's experiments (Settings, Experiments;
/// `cua-spaces-app-core` `experiments::Experiment::id`).
pub const EXPERIMENTS: &[&str] = &["cua_volume", "your_cloud", "sharing"];
+/// The Spaces app's interface language, as a fixed set: the languages it
+/// ships or plans to; any other language reads `other`. No region, no text.
+pub const UI_LOCALES: &[&str] = &["en", "zh-Hans", "ko", "pt-BR", "ja", "es", "other"];
/// An experiment's switch turned on or off.
pub const EXPERIMENT_ACTIONS: &[&str] = &["experiment_on", "experiment_off"];
pub const STREAM_TRANSPORTS: &[&str] = &["quic", "webrtc", "websocket", "grpc", "other"];
@@ -1160,16 +1163,23 @@ pub const EVENTS: &[EventSpec] = &[
},
EventSpec {
name: event::APP_ACTIVE,
- version: 2,
+ version: 3,
tier: Tier::Usage,
sample_rate: 1.0,
products: CLIENTS,
- props: &[p(
- "experiments_on",
- Kind::Set(EXPERIMENTS),
- "The Spaces app's experiments turned on in Settings, Experiments on this install (cua_volume, your_cloud, sharing, joined with +), or none.",
- )],
- purpose: "Retention (day 1, day 7, day 30) and daily and weekly active installs: at most one per install per UTC day, on a day the product is used. Also how many installs use each experiment.",
+ props: &[
+ p(
+ "experiments_on",
+ Kind::Set(EXPERIMENTS),
+ "The Spaces app's experiments turned on in Settings, Experiments on this install (cua_volume, your_cloud, sharing, joined with +), or none.",
+ ),
+ p(
+ "ui_locale",
+ Kind::Enum(UI_LOCALES),
+ "The Spaces app's interface language (en, zh-Hans, ko, pt-BR, ja, es), or other. en until the app says otherwise.",
+ ),
+ ],
+ purpose: "Retention (day 1, day 7, day 30) and daily and weekly active installs: at most one per install per UTC day, on a day the product is used. Also how many installs use each experiment, and which interface languages to ship.",
},
EventSpec {
name: event::ONBOARDING_PAGE,
diff --git a/libs/cua/crates/cua-telemetry/tests/privacy.rs b/libs/cua/crates/cua-telemetry/tests/privacy.rs
index 638d063b87..ebe929062c 100644
--- a/libs/cua/crates/cua-telemetry/tests/privacy.rs
+++ b/libs/cua/crates/cua-telemetry/tests/privacy.rs
@@ -140,7 +140,7 @@ fn all_builders(s: &str) -> Vec<Event> {
events::stream_summary(s, s, Some(true), 900, 1080, Some(40.0), d).unwrap(),
events::app_active(),
// Unknown experiment ids are dropped (`none`); known ones kept.
- events::app_active_with(&[s, "sharing", s]),
+ events::app_active_with(&[s, "sharing", s], s),
events::space_create(
&events::SpaceCreate {
on: s,
@@ -1279,6 +1279,61 @@ fn the_active_day_carries_the_experiments_that_are_on() {
assert!(!h2.path().join("telemetry/experiments_on").exists());
}
+/// `ui_locale`: the Spaces app's interface language, one of a fixed set
+/// (anything else is `other`), kept for the day's `cua_app_active`; `en`
+/// before the app says; nothing written while telemetry is off.
+#[test]
+fn the_active_day_carries_the_ui_locale() {
+ let k = Kind::Enum(schema::UI_LOCALES);
+ for ok in ["en", "zh-Hans", "ko", "pt-BR", "ja", "es", "other"] {
+ assert!(schema::value_ok(k, &Value::from(ok)), "{ok}");
+ }
+ for bad in [
+ "",
+ "fr",
+ "en-US",
+ "zh-Hant",
+ "EN",
+ "/Users/alice",
+ "Paris, France",
+ ] {
+ assert!(!schema::value_ok(k, &Value::from(bad)), "{bad}");
+ }
+ assert_eq!(events::ui_locale("ja"), "ja");
+ assert_eq!(events::ui_locale(" pt-BR\n"), "pt-BR");
+ for other in ["", "fr", "en-US", "ja-JP", "[email protected]", "other"] {
+ assert_eq!(events::ui_locale(other), "other", "{other}");
+ }
+
+ let h = tempfile::tempdir().unwrap();
+ let (t, sink) = ready(h.path(), &[]);
+ assert_eq!(t.capture_active_on(20_000), Captured::Queued);
+ t.set_ui_locale("ko");
+ // The next day, another process of the same install.
+ let (t2, sink2) = ready(h.path(), &[]);
+ assert_eq!(t2.capture_active_on(20_001), Captured::Queued);
+ t.set_ui_locale("fr-CA");
+ let (t3, sink3) = ready(h.path(), &[]);
+ assert_eq!(t3.capture_active_on(20_002), Captured::Queued);
+ for x in [&t, &t2, &t3] {
+ x.flush(Duration::from_secs(1));
+ }
+ let locales = |s: &MemorySink| -> Vec<String> {
+ s.events()
+ .iter()
+ .filter(|e| e["event"] == "cua_app_active")
+ .map(|e| e["properties"]["ui_locale"].as_str().unwrap().to_string())
+ .collect()
+ };
+ assert_eq!(locales(&sink), ["en"], "en before the app says");
+ assert_eq!(locales(&sink2), ["ko"]);
+ assert_eq!(locales(&sink3), ["other"]);
+ let h2 = tempfile::tempdir().unwrap();
+ let (off, _) = ready(h2.path(), &[("DO_NOT_TRACK", "1")]);
+ off.set_ui_locale("ja");
+ assert!(!h2.path().join("telemetry/ui_locale").exists());
+}
+
#[test]
fn stream_summary_is_bucketed_and_needs_video() {
let e = events::stream_summary(