Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add call events
Joseph T. Lyons98a0113ac398
diff --git a/crates/call/src/call.rs b/crates/call/src/call.rsindex 0a8f150194e..ed5e5602183 100644--- a/crates/call/src/call.rs+++ b/crates/call/src/call.rs@@ -4,7 +4,7 @@ pub mod room;use std::sync::Arc;use anyhow::{anyhow, Result};-use client::{proto, Client, TypedEnvelope, User, UserStore};+use client::{proto, ClickhouseEvent, Client, TelemetrySettings, TypedEnvelope, User, UserStore};use collections::HashSet;use futures::{future::Shared, FutureExt};use postage::watch;@@ -198,6 +198,7 @@ impl ActiveCall {let result = invite.await;this.update(&mut cx, |this, cx| {this.pending_invites.remove(&called_user_id);+ this.report_call_event("invite", cx);cx.notify();});result@@ -243,21 +244,26 @@ impl ActiveCall {};let join = Room::join(&call, self.client.clone(), self.user_store.clone(), cx);+cx.spawn(|this, mut cx| async move {let room = join.await?;this.update(&mut cx, |this, cx| this.set_room(Some(room.clone()), cx)).await?;+ this.update(&mut cx, |this, cx| {+ this.report_call_event("accept incoming", cx)+ });Ok(())})}- pub fn decline_incoming(&mut self) -> Result<()> {+ pub fn decline_incoming(&mut self, cx: &mut ModelContext<Self>) -> Result<()> {let call = self.incoming_call.0.borrow_mut().take().ok_or_else(|| anyhow!("no incoming call"))?;+ self.report_call_event_for_room("decline incoming", call.room_id, cx);self.client.send(proto::DeclineCall {room_id: call.room_id,})?;@@ -266,6 +272,7 @@ impl ActiveCall {pub fn hang_up(&mut self, cx: &mut ModelContext<Self>) -> Task<Result<()>> {cx.notify();+ self.report_call_event("hang up", cx);if let Some((room, _)) = self.room.take() {room.update(cx, |room, cx| room.leave(cx))} else {@@ -273,12 +280,28 @@ impl ActiveCall {}}+ pub fn toggle_screen_sharing(&self, cx: &mut AppContext) {+ if let Some(room) = self.room().cloned() {+ let toggle_screen_sharing = room.update(cx, |room, cx| {+ if room.is_screen_sharing() {+ self.report_call_event("disable screen share", cx);+ Task::ready(room.unshare_screen(cx))+ } else {+ self.report_call_event("enable screen share", cx);+ room.share_screen(cx)+ }+ });+ toggle_screen_sharing.detach_and_log_err(cx);+ }+ }+pub fn share_project(&mut self,project: ModelHandle<Project>,cx: &mut ModelContext<Self>,) -> Task<Result<u64>> {if let Some((room, _)) = self.room.as_ref() {+ self.report_call_event("share project", cx);room.update(cx, |room, cx| room.share_project(project, cx))} else {Task::ready(Err(anyhow!("no active call")))@@ -291,6 +314,7 @@ impl ActiveCall {cx: &mut ModelContext<Self>,) -> Result<()> {if let Some((room, _)) = self.room.as_ref() {+ self.report_call_event("unshare project", cx);room.update(cx, |room, cx| room.unshare_project(project, cx))} else {Err(anyhow!("no active call"))@@ -352,4 +376,19 @@ impl ActiveCall {pub fn pending_invites(&self) -> &HashSet<u64> {&self.pending_invites}++ fn report_call_event(&self, operation: &'static str, cx: &AppContext) {+ if let Some(room) = self.room() {+ self.report_call_event_for_room(operation, room.read(cx).id(), cx)+ }+ }++ fn report_call_event_for_room(&self, operation: &'static str, room_id: u64, cx: &AppContext) {+ let telemetry = self.client.telemetry();+ let telemetry_settings = *settings::get::<TelemetrySettings>(cx);++ let event = ClickhouseEvent::Call { operation, room_id };++ telemetry.report_clickhouse_event(event, telemetry_settings);+ }}diff --git a/crates/client/src/telemetry.rs b/crates/client/src/telemetry.rsindex 9c4e187dbc9..959f4cc7835 100644--- a/crates/client/src/telemetry.rs+++ b/crates/client/src/telemetry.rs@@ -70,6 +70,10 @@ pub enum ClickhouseEvent {suggestion_accepted: bool,file_extension: Option<String>,},+ Call {+ operation: &'static str,+ room_id: u64,+ },}#[cfg(debug_assertions)]diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rsindex 66dc19d6906..c32129818fd 100644--- a/crates/collab/src/tests/integration_tests.rs+++ b/crates/collab/src/tests/integration_tests.rs@@ -157,7 +157,7 @@ async fn test_basic_calls(// User C receives the call, but declines it.let call_c = incoming_call_c.next().await.unwrap().unwrap();assert_eq!(call_c.calling_user.github_login, "user_b");- active_call_c.update(cx_c, |call, _| call.decline_incoming().unwrap());+ active_call_c.update(cx_c, |call, cx| call.decline_incoming(cx).unwrap());assert!(incoming_call_c.next().await.unwrap().is_none());deterministic.run_until_parked();@@ -1080,7 +1080,7 @@ async fn test_calls_on_multiple_connections(// User B declines the call on one of the two connections, causing both connections// to stop ringing.- active_call_b2.update(cx_b2, |call, _| call.decline_incoming().unwrap());+ active_call_b2.update(cx_b2, |call, cx| call.decline_incoming(cx).unwrap());deterministic.run_until_parked();assert!(incoming_call_b1.next().await.unwrap().is_none());assert!(incoming_call_b2.next().await.unwrap().is_none());@@ -5945,7 +5945,7 @@ async fn test_contacts([("user_b".to_string(), "online", "busy")]);- active_call_b.update(cx_b, |call, _| call.decline_incoming().unwrap());+ active_call_b.update(cx_b, |call, cx| call.decline_incoming(cx).unwrap());deterministic.run_until_parked();assert_eq!(contacts(&client_a, cx_a),diff --git a/crates/collab/src/tests/randomized_integration_tests.rs b/crates/collab/src/tests/randomized_integration_tests.rsindex f5dfe17d6f3..8062a12b832 100644--- a/crates/collab/src/tests/randomized_integration_tests.rs+++ b/crates/collab/src/tests/randomized_integration_tests.rs@@ -365,7 +365,7 @@ async fn apply_client_operation(}log::info!("{}: declining incoming call", client.username);- active_call.update(cx, |call, _| call.decline_incoming())?;+ active_call.update(cx, |call, cx| call.decline_incoming(cx))?;}ClientOperation::LeaveCall => {diff --git a/crates/collab_ui/src/collab_ui.rs b/crates/collab_ui/src/collab_ui.rsindex 76f2e265711..3f5ca17a20e 100644--- a/crates/collab_ui/src/collab_ui.rs+++ b/crates/collab_ui/src/collab_ui.rs@@ -11,7 +11,7 @@ mod sharing_status_indicator;use call::{ActiveCall, Room};pub use collab_titlebar_item::{CollabTitlebarItem, ToggleContactsMenu};-use gpui::{actions, AppContext, Task};+use gpui::{actions, AppContext};use std::sync::Arc;use util::ResultExt;use workspace::AppState;@@ -44,16 +44,9 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut AppContext) {}pub fn toggle_screen_sharing(_: &ToggleScreenSharing, cx: &mut AppContext) {- if let Some(room) = ActiveCall::global(cx).read(cx).room().cloned() {- let toggle_screen_sharing = room.update(cx, |room, cx| {- if room.is_screen_sharing() {- Task::ready(room.unshare_screen(cx))- } else {- room.share_screen(cx)- }- });- toggle_screen_sharing.detach_and_log_err(cx);- }+ ActiveCall::global(cx).update(cx, |call, cx| {+ call.toggle_screen_sharing(cx);+ });}pub fn toggle_mute(_: &ToggleMute, cx: &mut AppContext) {diff --git a/crates/collab_ui/src/incoming_call_notification.rs b/crates/collab_ui/src/incoming_call_notification.rsindex 12fad467e34..4066b5b229a 100644--- a/crates/collab_ui/src/incoming_call_notification.rs+++ b/crates/collab_ui/src/incoming_call_notification.rs@@ -99,8 +99,8 @@ impl IncomingCallNotification {}).detach_and_log_err(cx);} else {- active_call.update(cx, |active_call, _| {- active_call.decline_incoming().log_err();+ active_call.update(cx, |active_call, cx| {+ active_call.decline_incoming(cx).log_err();});}}diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 28edd2a460f..85a428d8011 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -7565,7 +7565,7 @@ impl Editor {fn report_editor_event(&self,- name: &'static str,+ operation: &'static str,file_extension: Option<String>,cx: &AppContext,) {@@ -7602,7 +7602,7 @@ impl Editor {let event = ClickhouseEvent::Editor {file_extension,vim_mode,- operation: name,+ operation,copilot_enabled,copilot_enabled_for_language,};