From f9420acdfd2221718b45b48d8a089a9f1551f1cd Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:21:41 +0100 Subject: [PATCH 1/7] Remove unhelpful Client self fields from tracing spans Client's Debug implementation just returns "Client". --- crates/matrix-sdk/src/client/mod.rs | 12 ++++++------ crates/matrix-sdk/src/encryption/mod.rs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index e8a161bf4..3a1560167 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -697,7 +697,7 @@ impl Client { /// ``` /// /// [`restore_login`]: #method.restore_login - #[instrument(skip(user, password))] + #[instrument(skip(self, user, password))] pub async fn login( &self, user: impl AsRef, @@ -985,7 +985,7 @@ impl Client { /// /// [`get_sso_login_url`]: #method.get_sso_login_url /// [`restore_login`]: #method.restore_login - #[instrument(skip(token))] + #[instrument(skip(self, token))] #[cfg_attr(not(target_arch = "wasm32"), deny(clippy::future_not_send))] pub async fn login_with_token( &self, @@ -1128,7 +1128,7 @@ impl Client { /// client.register(request).await; /// # }) /// ``` - #[instrument(skip(registration))] + #[instrument(skip_all)] pub async fn register( &self, registration: impl Into>, @@ -1666,7 +1666,7 @@ impl Client { /// [`get_or_upload_filter()`]: #method.get_or_upload_filter /// [long polling]: #long-polling /// [filtered]: #filtering-events - #[instrument] + #[instrument(skip(self))] pub async fn sync_once( &self, sync_settings: crate::config::SyncSettings<'_>, @@ -1815,7 +1815,7 @@ impl Client { /// .await; /// }) /// ``` - #[instrument(skip(callback))] + #[instrument(skip(self, callback))] pub async fn sync_with_callback( &self, mut sync_settings: crate::config::SyncSettings<'_>, @@ -1885,7 +1885,7 @@ impl Client { /// /// # Result::<_, matrix_sdk::Error>::Ok(()) }); /// ``` - #[instrument] + #[instrument(skip(self))] pub async fn sync_stream<'a>( &'a self, mut sync_settings: crate::config::SyncSettings<'a>, diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 2f5810744..7500e2071 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -95,7 +95,7 @@ impl Client { /// /// Panics if no key query needs to be done. #[cfg(feature = "encryption")] - #[instrument] + #[instrument(skip(self))] pub(crate) async fn keys_query( &self, request_id: &TransactionId, @@ -313,7 +313,7 @@ impl Client { /// /// * `users` - The list of user/device pairs that we should claim keys for. #[cfg(feature = "encryption")] - #[instrument(skip(users))] + #[instrument(skip_all)] pub(crate) async fn claim_one_time_keys( &self, users: impl Iterator, @@ -338,7 +338,7 @@ impl Client { /// Panics if the client isn't logged in, or if no encryption keys need to /// be uploaded. #[cfg(feature = "encryption")] - #[instrument] + #[instrument(skip(self))] pub(crate) async fn keys_upload( &self, request_id: &TransactionId, From 5ff38eff00b80ed1a7757a11659b0d284b0547af Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:22:12 +0100 Subject: [PATCH 2/7] Activate tracing-subscriber's env-filter feature This allows the log level of examples to be controlled using the RUST_LOG environment variable. --- crates/matrix-sdk/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index dd95cfd6b..9467287dc 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -142,7 +142,7 @@ matrix-sdk-test = { version = "0.4.0", path = "../matrix-sdk-test" } mockito = "0.30.0" serde_json = "1.0.64" tempfile = "3.2.0" -tracing-subscriber = "0.3.7" +tracing-subscriber = { version = "0.3.7", features = ["env-filter"] } [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies.tokio] From c9c31fa1c28f166995e43eb57fd277f4b2d8a976 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:22:40 +0100 Subject: [PATCH 3/7] Simplify SyncSettings::default() --- crates/matrix-sdk/src/config/sync.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/matrix-sdk/src/config/sync.rs b/crates/matrix-sdk/src/config/sync.rs index e9194040e..b19b77522 100644 --- a/crates/matrix-sdk/src/config/sync.rs +++ b/crates/matrix-sdk/src/config/sync.rs @@ -29,12 +29,7 @@ pub struct SyncSettings<'a> { impl<'a> Default for SyncSettings<'a> { fn default() -> Self { - Self { - filter: Default::default(), - timeout: Some(DEFAULT_SYNC_TIMEOUT), - token: Default::default(), - full_state: Default::default(), - } + Self { filter: None, timeout: Some(DEFAULT_SYNC_TIMEOUT), token: None, full_state: false } } } From baa869552f4557fbf6bcf56bbf2cefa25722387c Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:23:11 +0100 Subject: [PATCH 4/7] Implement Default for SyncSettings in terms of SyncSettings::new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … rather than the other way around. --- crates/matrix-sdk/src/config/sync.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/config/sync.rs b/crates/matrix-sdk/src/config/sync.rs index b19b77522..d2a761e16 100644 --- a/crates/matrix-sdk/src/config/sync.rs +++ b/crates/matrix-sdk/src/config/sync.rs @@ -29,7 +29,7 @@ pub struct SyncSettings<'a> { impl<'a> Default for SyncSettings<'a> { fn default() -> Self { - Self { filter: None, timeout: Some(DEFAULT_SYNC_TIMEOUT), token: None, full_state: false } + Self::new() } } @@ -37,7 +37,7 @@ impl<'a> SyncSettings<'a> { /// Create new default sync settings. #[must_use] pub fn new() -> Self { - Default::default() + Self { filter: None, timeout: Some(DEFAULT_SYNC_TIMEOUT), token: None, full_state: false } } /// Set the sync token. From ea3ca1a8ca789ec14556503795ddc104500f07d8 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:23:53 +0100 Subject: [PATCH 5/7] Remove unnecessary semicolons after if-let expressions --- crates/matrix-sdk/src/client/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 3a1560167..c66f15f87 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1680,7 +1680,7 @@ impl Client { #[cfg(feature = "encryption")] if let Err(e) = self.send_outgoing_requests().await { error!(error =? e, "Error while sending outgoing E2EE requests"); - }; + } let request = assign!(sync_events::v3::Request::new(), { filter: sync_settings.filter.as_ref(), @@ -1701,7 +1701,7 @@ impl Client { #[cfg(feature = "encryption")] if let Err(e) = self.send_outgoing_requests().await { error!(error =? e, "Error while sending outgoing E2EE requests"); - }; + } self.inner.sync_beat.notify(usize::MAX); From 7b8568f5c8367d31c7022090e4d973111ef1a6a4 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:24:50 +0100 Subject: [PATCH 6/7] Simplify get_or_upload_filter example --- crates/matrix-sdk/src/client/mod.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index c66f15f87..a301b48ab 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1177,15 +1177,10 @@ impl Client { /// # let homeserver = Url::parse("http://example.com").unwrap(); /// # let client = Client::new(homeserver).await.unwrap(); /// let mut filter = FilterDefinition::default(); - /// let mut room_filter = RoomFilter::default(); - /// let mut event_filter = RoomEventFilter::default(); /// /// // Let's enable member lazy loading. - /// event_filter.lazy_load_options = LazyLoadOptions::Enabled { - /// include_redundant_members: false, - /// }; - /// room_filter.state = event_filter; - /// filter.room = room_filter; + /// filter.room.state.lazy_load_options = + /// LazyLoadOptions::Enabled { include_redundant_members: false }; /// /// let filter_id = client /// .get_or_upload_filter("sync", filter) From 5b5e13fe2c2aa46c354604d77a0793e6fe13f26e Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Mar 2022 14:26:28 +0100 Subject: [PATCH 7/7] Remove request field from Client::keys_upload tracing span It results in a lot of log noise for initial syncs. --- crates/matrix-sdk/src/encryption/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 7500e2071..14e61eab9 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -338,7 +338,7 @@ impl Client { /// Panics if the client isn't logged in, or if no encryption keys need to /// be uploaded. #[cfg(feature = "encryption")] - #[instrument(skip(self))] + #[instrument(skip(self, request))] pub(crate) async fn keys_upload( &self, request_id: &TransactionId,