diff --git a/docker-compose.yml b/docker-compose.yml index 010acd89..3a8069b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,6 +71,7 @@ services: appflowy_cloud: restart: on-failure environment: + - RUST_LOG=trace - APP_ENVIRONMENT=production - APP__GOTRUE__JWT_SECRET=${GOTRUE_JWT_SECRET} - APP__GOTRUE__EXT_URL=${API_EXTERNAL_URL} diff --git a/libs/client-api/src/collab_sync/sink.rs b/libs/client-api/src/collab_sync/sink.rs index 6667a340..2fd62a18 100644 --- a/libs/client-api/src/collab_sync/sink.rs +++ b/libs/client-api/src/collab_sync/sink.rs @@ -163,7 +163,12 @@ where let is_done = pending_msg.set_state(self.uid, MessageState::Done); if is_done { - trace!("[Client {}]: Did send: {}:{}", self.uid, object_id, msg_id); + trace!( + "[Client {}]: did send oid:{}|msg_id{} ", + self.uid, + object_id, + msg_id + ); self.notify(); } is_done diff --git a/libs/client-api/src/http.rs b/libs/client-api/src/http.rs index 7445bc98..71ea18b6 100644 --- a/libs/client-api/src/http.rs +++ b/libs/client-api/src/http.rs @@ -20,6 +20,7 @@ use shared_entity::dto::UserUpdateParams; use shared_entity::dto::WorkspaceMembersParams; use std::sync::Arc; use std::time::SystemTime; +use tracing::instrument; use gotrue_entity::{AccessTokenResponse, User}; @@ -153,6 +154,7 @@ impl Client { /// - `Ok(String)`: A `String` containing the constructed authorization URL if the specified provider is available. /// - `Err(AppError)`: An `AppError` indicating either the OAuth provider is invalid or other issues occurred while fetching settings. /// + #[instrument(level = "debug", skip_all, err)] pub async fn generate_oauth_url_with_provider( &self, provider: &OAuthProvider, @@ -172,6 +174,7 @@ impl Client { /// Returns an OAuth URL by constructing the authorization URL for the specified provider. /// The URL looks like, e.g., `appflowy-flutter://#access_token=...&expires_in=3600&provider_token=...&refresh_token=...&token_type=bearer`. /// + #[instrument(level = "debug", skip_all, err)] pub async fn generate_sign_in_url_with_email( &self, admin_user_email: &str, @@ -210,6 +213,7 @@ impl Client { Ok((user, is_new)) } + #[instrument(level = "debug", skip_all, err)] #[inline] async fn verify_token_cloud(&self, access_token: &str) -> Result { let url = format!("{}/api/user/verify/{}", self.base_url, access_token); @@ -218,6 +222,7 @@ impl Client { Ok(sign_in_resp.is_new) } + #[instrument(level = "debug", skip_all, err)] pub async fn create_magic_link(&self, email: &str, password: &str) -> Result { let user = self .gotrue_client @@ -234,6 +239,7 @@ impl Client { Ok(user) } + #[instrument(level = "debug", skip_all, err)] pub async fn create_email_verified_user( &self, email: &str, @@ -297,6 +303,7 @@ impl Client { } } + #[instrument(level = "debug", skip_all, err)] pub async fn profile(&self) -> Result { let url = format!("{}/api/user/profile", self.base_url); let resp = self @@ -309,6 +316,7 @@ impl Client { .into_data() } + #[instrument(level = "debug", skip_all, err)] pub async fn workspaces(&self) -> Result { let url = format!("{}/api/workspace/list", self.base_url); let resp = self @@ -321,6 +329,7 @@ impl Client { .into_data() } + #[instrument(level = "debug", skip_all, err)] pub async fn get_workspace_members( &self, workspace_uuid: uuid::Uuid, @@ -339,6 +348,7 @@ impl Client { .into_data() } + #[instrument(level = "debug", skip_all, err)] pub async fn add_workspace_members( &self, workspace_uuid: uuid::Uuid, @@ -359,6 +369,7 @@ impl Client { Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn remove_workspace_members( &self, workspace_uuid: uuid::Uuid, @@ -379,6 +390,7 @@ impl Client { Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn sign_in_password(&self, email: &str, password: &str) -> Result { let access_token_resp = self .gotrue_client @@ -399,6 +411,7 @@ impl Client { /// This function attempts to refresh the access token by sending a request to the authentication server /// using the stored refresh token. If successful, it updates the stored access token with the new one /// received from the server. + #[instrument(level = "debug", skip_all, err)] pub async fn refresh(&self) -> Result<(), AppError> { let refresh_token = self .token @@ -416,6 +429,7 @@ impl Client { Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn sign_up(&self, email: &str, password: &str) -> Result<(), AppError> { match self.gotrue_client.sign_up(email, password).await? { Authenticated(access_token_resp) => { @@ -429,11 +443,13 @@ impl Client { } } + #[instrument(level = "debug", skip_all, err)] pub async fn sign_out(&self) -> Result<(), AppError> { self.gotrue_client.logout(&self.access_token()?).await?; Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn update(&self, params: UserUpdateParams) -> Result<(), AppError> { let updated_user = self .gotrue_client @@ -448,6 +464,7 @@ impl Client { Ok(()) } + #[instrument(level = "debug", skip_all, err)] pub async fn update_user_name(&self, new_name: &str) -> Result<(), AppError> { let url = format!("{}/api/user/update", self.base_url); let params = UpdateUsernameParams { @@ -462,6 +479,7 @@ impl Client { AppResponse::<()>::from_response(resp).await?.into_error() } + #[instrument(level = "debug", skip_all, err)] pub async fn create_collab(&self, params: InsertCollabParams) -> Result<(), AppError> { let url = format!("{}/api/collab/", self.base_url); let resp = self @@ -473,6 +491,7 @@ impl Client { AppResponse::<()>::from_response(resp).await?.into_error() } + #[instrument(level = "debug", skip_all, err)] pub async fn update_collab(&self, params: InsertCollabParams) -> Result<(), AppError> { let url = format!("{}/api/collab/", self.base_url); let resp = self @@ -484,6 +503,7 @@ impl Client { AppResponse::<()>::from_response(resp).await?.into_error() } + #[instrument(level = "debug", skip_all, err)] pub async fn get_collab(&self, params: QueryCollabParams) -> Result { let url = format!("{}/api/collab/", self.base_url); let resp = self @@ -497,6 +517,7 @@ impl Client { .into_data() } + #[instrument(level = "debug", skip_all, err)] pub async fn delete_collab(&self, params: DeleteCollabParams) -> Result<(), AppError> { let url = format!("{}/api/collab/", self.base_url); let resp = self diff --git a/libs/client-api/src/ws/client.rs b/libs/client-api/src/ws/client.rs index 59241fd2..3ed2556e 100644 --- a/libs/client-api/src/ws/client.rs +++ b/libs/client-api/src/ws/client.rs @@ -192,7 +192,7 @@ impl WSClient { .channels .write() .entry(business_id) - .or_insert_with(HashMap::new) + .or_default() .insert(object_id, Arc::downgrade(&channel)); Ok(channel) } @@ -221,7 +221,6 @@ impl WSClient { } async fn set_state(&self, state: ConnectState) { - trace!("websocket state: {:?}", state); self.state_notify.lock().set_state(state); } } diff --git a/libs/client-api/src/ws/ping.rs b/libs/client-api/src/ws/ping.rs index bea68d26..d745c17d 100644 --- a/libs/client-api/src/ws/ping.rs +++ b/libs/client-api/src/ws/ping.rs @@ -51,8 +51,6 @@ impl ServerFixIntervalPing { loop { tokio::select! { _ = interval.tick() => { - // Send the ping - tracing::trace!("🟢ping from client"); let _ = sender.send(Message::Ping(vec![])); if let Some(ping_count) = weak_ping_count.upgrade() { let mut lock = ping_count.lock().await; @@ -67,7 +65,6 @@ impl ServerFixIntervalPing { }, msg = receiver.recv() => { if let Ok(Message::Pong(_)) = msg { - tracing::trace!("🟢pong from server"); if let Some(ping_count) = weak_ping_count.upgrade() { let mut lock = ping_count.lock().await; *lock = 0; diff --git a/libs/client-api/src/ws/state.rs b/libs/client-api/src/ws/state.rs index dc4057d4..78cf9ad5 100644 --- a/libs/client-api/src/ws/state.rs +++ b/libs/client-api/src/ws/state.rs @@ -16,7 +16,7 @@ impl ConnectStateNotify { pub(crate) fn set_state(&mut self, state: ConnectState) { if self.state != state { - tracing::trace!("[🙂Client]: connect state changed to {:?}", state); + tracing::trace!("[WS]: {:?}", state); self.state = state.clone(); let _ = self.sender.send(state); } diff --git a/libs/database-entity/src/database_error.rs b/libs/database-entity/src/database_error.rs index 53f9acdf..a858ba23 100644 --- a/libs/database-entity/src/database_error.rs +++ b/libs/database-entity/src/database_error.rs @@ -1,6 +1,6 @@ #[derive(Debug, thiserror::Error)] pub enum DatabaseError { - #[error("Record not found")] + #[error("Database not found")] RecordNotFound, #[error(transparent)] diff --git a/libs/shared-entity/src/app_error.rs b/libs/shared-entity/src/app_error.rs index 0d2d4b9d..94b5f3cc 100644 --- a/libs/shared-entity/src/app_error.rs +++ b/libs/shared-entity/src/app_error.rs @@ -26,7 +26,7 @@ impl AppError { impl Display for AppError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.message) + f.write_fmt(format_args!("code:{} msg: {}", self.code, self.message)) } } diff --git a/src/biz/user.rs b/src/biz/user.rs index aefc0dc1..e1f4d6c5 100644 --- a/src/biz/user.rs +++ b/src/biz/user.rs @@ -43,5 +43,5 @@ fn name_from_user_metadata(value: &serde_json::Value) -> String { .or(value.get("nickname")) .and_then(serde_json::Value::as_str) .map(str::to_string) - .unwrap_or(String::new()) + .unwrap_or_default() }