From 4f1a65af60e09e074c84d269ce006a2c3fa82aae Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Fri, 27 Feb 2026 17:24:40 +0100 Subject: [PATCH 1/2] fix: make instrumentation optional Allows to stop instrumenting functions which prevents from massive log entries due to logged structures. --- crates/matrix-sdk-base/Cargo.toml | 3 + crates/matrix-sdk-base/src/client.rs | 6 +- .../account_data/global.rs | 4 +- .../response_processors/account_data/room.rs | 4 +- .../src/response_processors/changes.rs | 6 +- .../src/response_processors/state_events.rs | 6 +- .../src/response_processors/timeline.rs | 4 +- crates/matrix-sdk-base/src/room/mod.rs | 4 +- crates/matrix-sdk-base/src/room/room_info.rs | 6 +- crates/matrix-sdk-base/src/sliding_sync.rs | 4 +- .../src/store/ambiguity_map.rs | 4 +- .../matrix-sdk-base/src/store/memory_store.rs | 6 +- crates/matrix-sdk-common/Cargo.toml | 3 + .../src/cross_process_lock.rs | 8 ++- crates/matrix-sdk-crypto/Cargo.toml | 3 + crates/matrix-sdk-crypto/src/backups/mod.rs | 4 +- .../src/gossiping/machine.rs | 7 ++- .../src/identities/manager.rs | 10 ++-- crates/matrix-sdk-crypto/src/machine/mod.rs | 31 ++++++---- crates/matrix-sdk-crypto/src/olm/account.rs | 11 ++-- .../src/session_manager/group_sessions/mod.rs | 11 ++-- .../group_sessions/share_strategy.rs | 4 +- .../src/session_manager/sessions.rs | 4 +- crates/matrix-sdk-crypto/src/store/caches.rs | 7 ++- crates/matrix-sdk-crypto/src/store/mod.rs | 4 +- .../src/verification/machine.rs | 4 +- crates/matrix-sdk-indexeddb/Cargo.toml | 2 + .../src/event_cache_store/mod.rs | 26 ++++----- .../src/media_store/mod.rs | 39 ++++++------- crates/matrix-sdk-sqlite/Cargo.toml | 3 + crates/matrix-sdk-sqlite/src/crypto_store.rs | 10 ++-- .../src/event_cache_store.rs | 32 +++++----- crates/matrix-sdk-sqlite/src/lib.rs | 2 + crates/matrix-sdk-sqlite/src/media_store.rs | 28 ++++----- crates/matrix-sdk-sqlite/src/state_store.rs | 6 +- crates/matrix-sdk-ui/Cargo.toml | 3 + .../src/encryption_sync_service.rs | 6 +- .../matrix-sdk-ui/src/notification_client.rs | 8 +-- crates/matrix-sdk-ui/src/sync_service.rs | 6 +- .../src/timeline/controller/mod.rs | 16 +++-- .../src/timeline/controller/read_receipts.rs | 12 ++-- .../src/timeline/controller/state.rs | 6 +- .../timeline/controller/state_transaction.rs | 6 +- .../src/timeline/date_dividers.rs | 4 +- .../src/timeline/event_handler.rs | 13 +++-- .../src/timeline/event_item/content/reply.rs | 4 +- crates/matrix-sdk-ui/src/timeline/mod.rs | 26 ++++----- .../matrix-sdk-ui/src/timeline/pagination.rs | 2 +- crates/matrix-sdk/Cargo.toml | 11 +++- .../authentication/matrix/login_builder.rs | 16 +++-- .../src/authentication/matrix/mod.rs | 6 +- .../authentication/oauth/auth_code_builder.rs | 7 ++- .../src/authentication/oauth/mod.rs | 4 +- .../qrcode/rendezvous_channel/msc_4108.rs | 6 +- .../oauth/qrcode/secure_channel/mod.rs | 6 +- crates/matrix-sdk/src/client/builder/mod.rs | 7 ++- crates/matrix-sdk/src/client/mod.rs | 16 ++--- .../src/client/thread_subscriptions.rs | 8 +-- .../matrix-sdk/src/encryption/backups/mod.rs | 10 ++-- crates/matrix-sdk/src/encryption/mod.rs | 8 +-- .../matrix-sdk/src/encryption/recovery/mod.rs | 18 +++--- .../encryption/secret_storage/secret_store.rs | 7 ++- crates/matrix-sdk/src/encryption/tasks.rs | 4 +- .../src/event_cache/caches/pagination.rs | 6 +- crates/matrix-sdk/src/event_cache/mod.rs | 4 +- crates/matrix-sdk/src/event_handler/mod.rs | 4 +- crates/matrix-sdk/src/room/calls.rs | 3 +- crates/matrix-sdk/src/room/edit.rs | 3 +- crates/matrix-sdk/src/room/mod.rs | 58 +++++++++---------- crates/matrix-sdk/src/room/reply.rs | 3 +- .../src/room/shared_room_history.rs | 6 +- crates/matrix-sdk/src/room_preview.rs | 4 +- crates/matrix-sdk/src/send_queue/mod.rs | 16 ++--- crates/matrix-sdk/src/send_queue/upload.rs | 10 ++-- .../matrix-sdk/src/sliding_sync/list/mod.rs | 7 +-- crates/matrix-sdk/src/sliding_sync/mod.rs | 12 ++-- crates/matrix-sdk/src/sync.rs | 4 +- crates/matrix-sdk/src/widget/machine/mod.rs | 14 ++--- 78 files changed, 389 insertions(+), 327 deletions(-) diff --git a/crates/matrix-sdk-base/Cargo.toml b/crates/matrix-sdk-base/Cargo.toml index f5e68489ab5..d79323d41f8 100644 --- a/crates/matrix-sdk-base/Cargo.toml +++ b/crates/matrix-sdk-base/Cargo.toml @@ -70,6 +70,9 @@ unstable-msc4274 = [] experimental-element-recent-emojis = [] +# tracing #[instrument]'ation +instrument = ["matrix-sdk-common/instrument", "matrix-sdk-crypto?/instrument"] + [dependencies] as_variant.workspace = true assert_matches = { workspace = true, optional = true } diff --git a/crates/matrix-sdk-base/src/client.rs b/crates/matrix-sdk-base/src/client.rs index 7e48f08761a..0ef82823891 100644 --- a/crates/matrix-sdk-base/src/client.rs +++ b/crates/matrix-sdk-base/src/client.rs @@ -50,7 +50,7 @@ use ruma::{ use tokio::sync::{Mutex, broadcast}; #[cfg(feature = "e2e-encryption")] use tokio::sync::{RwLock, RwLockReadGuard}; -use tracing::{Level, debug, enabled, info, instrument, warn}; +use tracing::{Level, debug, enabled, info, warn}; #[cfg(feature = "e2e-encryption")] use crate::RoomMemberships; @@ -553,7 +553,7 @@ impl BaseClient { /// # Arguments /// /// * `response` - The response that we received after a successful sync. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn receive_sync_response( &self, response: api::sync::sync_events::v3::Response, @@ -816,7 +816,7 @@ impl BaseClient { /// * `room_id` - The room id this response belongs to. /// /// * `response` - The raw response that was received from the server. - #[instrument(skip_all, fields(?room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?room_id)))] pub async fn receive_all_members( &self, room_id: &RoomId, diff --git a/crates/matrix-sdk-base/src/response_processors/account_data/global.rs b/crates/matrix-sdk-base/src/response_processors/account_data/global.rs index 6ee86c9132b..fec137713d5 100644 --- a/crates/matrix-sdk-base/src/response_processors/account_data/global.rs +++ b/crates/matrix-sdk-base/src/response_processors/account_data/global.rs @@ -25,7 +25,7 @@ use ruma::{ }, serde::Raw, }; -use tracing::{debug, instrument, trace, warn}; +use tracing::{debug, trace, warn}; use super::super::Context; use crate::{RoomInfo, StateChanges, store::BaseStateStore}; @@ -76,7 +76,7 @@ impl Global { /// Given a [`StateChanges`] instance, processes any direct room info /// from the global account data and adds it to the room infos to /// save. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn process_direct_rooms( &self, events: &[AnyGlobalAccountDataEvent], diff --git a/crates/matrix-sdk-base/src/response_processors/account_data/room.rs b/crates/matrix-sdk-base/src/response_processors/account_data/room.rs index 638c2d2db9a..5ace164979f 100644 --- a/crates/matrix-sdk-base/src/response_processors/account_data/room.rs +++ b/crates/matrix-sdk-base/src/response_processors/account_data/room.rs @@ -17,7 +17,7 @@ use ruma::{ events::{AnyRoomAccountDataEvent, marked_unread::MarkedUnreadEventContent}, serde::Raw, }; -use tracing::{instrument, warn}; +use tracing::warn; use super::super::{Context, RoomInfoNotableUpdates}; use crate::{ @@ -25,7 +25,7 @@ use crate::{ store::BaseStateStore, }; -#[instrument(skip_all, fields(?room_id))] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?room_id)))] pub fn for_room( context: &mut Context, room_id: &RoomId, diff --git a/crates/matrix-sdk-base/src/response_processors/changes.rs b/crates/matrix-sdk-base/src/response_processors/changes.rs index f6bc0162beb..b547a41f45e 100644 --- a/crates/matrix-sdk-base/src/response_processors/changes.rs +++ b/crates/matrix-sdk-base/src/response_processors/changes.rs @@ -18,7 +18,7 @@ use ruma::{ events::{GlobalAccountDataEventType, ignored_user_list::IgnoredUserListEvent}, serde::Raw, }; -use tracing::{error, instrument, trace}; +use tracing::{error, trace}; use super::Context; use crate::{ @@ -28,7 +28,7 @@ use crate::{ /// Save the [`StateChanges`] from the [`Context`] inside the [`BaseStateStore`] /// only! The changes aren't applied on the in-memory rooms. -#[instrument(skip_all)] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn save_only(context: Context, state_store: &BaseStateStore) -> Result<()> { let _timer = timer!(tracing::Level::TRACE, "_method"); @@ -40,7 +40,7 @@ pub async fn save_only(context: Context, state_store: &BaseStateStore) -> Result /// Save the [`StateChanges`] from the [`Context`] inside the /// [`BaseStateStore`], and apply them on the in-memory rooms. -#[instrument(skip_all)] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn save_and_apply( context: Context, state_store: &BaseStateStore, diff --git a/crates/matrix-sdk-base/src/response_processors/state_events.rs b/crates/matrix-sdk-base/src/response_processors/state_events.rs index f82fcb13507..2c1799578a9 100644 --- a/crates/matrix-sdk-base/src/response_processors/state_events.rs +++ b/crates/matrix-sdk-base/src/response_processors/state_events.rs @@ -38,7 +38,6 @@ pub mod sync { AnySyncStateEvent, AnySyncTimelineEvent, StateEventType, room::member::MembershipState, }, }; - use tracing::instrument; use super::{super::profiles, Context, Raw}; #[cfg(feature = "experimental-encrypted-state-events")] @@ -88,7 +87,7 @@ pub mod sync { /// /// The `new_users` mutable reference allows to collect the new users for /// this room. - #[instrument(skip_all, fields(room_id = ?room_info.room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?room_info.room_id)))] pub async fn dispatch( context: &mut Context, raw_events: Vec>, @@ -268,7 +267,6 @@ pub mod stripped { events::{AnyStrippedStateEvent, StateEventType}, push::Action, }; - use tracing::instrument; use super::{ super::{notification, timeline}, @@ -304,7 +302,7 @@ pub mod stripped { /// * `room` - The [`Room`] to modify. /// * `room_info` - The current room's info. /// * `notifications` - Notifications to post for the current room. - #[instrument(skip_all, fields(room_id = ?room_info.room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?room_info.room_id)))] pub(crate) async fn dispatch_invite_or_knock( context: &mut Context, raw_events: Vec>, diff --git a/crates/matrix-sdk-base/src/response_processors/timeline.rs b/crates/matrix-sdk-base/src/response_processors/timeline.rs index fa48ee4caab..f7061000c66 100644 --- a/crates/matrix-sdk-base/src/response_processors/timeline.rs +++ b/crates/matrix-sdk-base/src/response_processors/timeline.rs @@ -20,7 +20,7 @@ use ruma::{ events::{AnySyncMessageLikeEvent, AnySyncTimelineEvent}, push::{Action, PushConditionRoomCtx}, }; -use tracing::{instrument, trace, warn}; +use tracing::{trace, warn}; use super::{Context, notification}; #[cfg(feature = "e2e-encryption")] @@ -36,7 +36,7 @@ use crate::{Result, Room, RoomInfo, sync::Timeline}; /// - will process redaction, /// - will process notification. #[allow(clippy::extra_unused_lifetimes)] -#[instrument(skip_all, fields(room_id = ?room_info.room_id))] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?room_info.room_id)))] pub async fn build<'notification, 'e2ee>( context: &mut Context, room: &Room, diff --git a/crates/matrix-sdk-base/src/room/mod.rs b/crates/matrix-sdk-base/src/room/mod.rs index 448fd38d471..802c4570390 100644 --- a/crates/matrix-sdk-base/src/room/mod.rs +++ b/crates/matrix-sdk-base/src/room/mod.rs @@ -65,7 +65,7 @@ pub use state::{RoomState, RoomStateFilter}; pub(crate) use tags::RoomNotableTags; use tokio::sync::broadcast; pub use tombstone::{PredecessorRoom, SuccessorRoom}; -use tracing::{info, instrument, warn}; +use tracing::{info, warn}; use crate::{ Error, @@ -271,7 +271,7 @@ impl Room { /// Is this room considered a direct message. /// /// Async because it can read room info from storage. - #[instrument(skip_all, fields(room_id = ?self.room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?self.room_id)))] pub async fn is_direct(&self) -> StoreResult { match self.state() { RoomState::Joined | RoomState::Left | RoomState::Banned => { diff --git a/crates/matrix-sdk-base/src/room/room_info.rs b/crates/matrix-sdk-base/src/room/room_info.rs index dbb0f11e839..7ce5735df56 100644 --- a/crates/matrix-sdk-base/src/room/room_info.rs +++ b/crates/matrix-sdk-base/src/room/room_info.rs @@ -58,7 +58,7 @@ use ruma::{ serde::Raw, }; use serde::{Deserialize, Serialize}; -use tracing::{field::debug, info, instrument, warn}; +use tracing::{field::debug, info, warn}; use super::{ AccountDataSource, EncryptionState, Room, RoomCreateWithCreatorEventContent, RoomDisplayName, @@ -798,7 +798,7 @@ impl RoomInfo { } /// Handle the given redaction. - #[instrument(skip_all, fields(redacts))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(redacts)))] pub fn handle_redaction( &mut self, event: &SyncRoomRedactionEvent, @@ -1182,7 +1182,7 @@ impl RoomInfo { /// /// Returns `true` if migrations were applied and this `RoomInfo` needs to /// be persisted to the state store. - #[instrument(skip_all, fields(room_id = ?self.room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?self.room_id)))] pub(crate) async fn apply_migrations(&mut self, store: Arc) -> bool { let mut migrated = false; diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index e86277ce67a..bff45dc3d64 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -21,7 +21,7 @@ use ruma::{ OwnedRoomId, api::client::sync::sync_events::v5 as http, events::receipt::SyncReceiptEvent, serde::Raw, }; -use tracing::{instrument, trace}; +use tracing::trace; use super::BaseClient; use crate::{ @@ -89,7 +89,7 @@ impl BaseClient { /// /// * `response` - The response that we received after a successful sliding /// sync. - #[instrument(skip_all, level = "trace")] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, level = "trace"))] pub async fn process_sliding_sync( &self, response: &http::Response, diff --git a/crates/matrix-sdk-base/src/store/ambiguity_map.rs b/crates/matrix-sdk-base/src/store/ambiguity_map.rs index ba4d3b2f775..4e14c7a104c 100644 --- a/crates/matrix-sdk-base/src/store/ambiguity_map.rs +++ b/crates/matrix-sdk-base/src/store/ambiguity_map.rs @@ -21,7 +21,7 @@ use ruma::{ OwnedEventId, OwnedRoomId, OwnedUserId, RoomId, UserId, events::room::member::{MembershipState, SyncRoomMemberEvent}, }; -use tracing::{instrument, trace}; +use tracing::trace; use super::{DynStateStore, Result, StateChanges}; use crate::{ @@ -79,7 +79,7 @@ pub(crate) struct AmbiguityCache { pub changes: BTreeMap>, } -#[instrument(ret(level = "trace"))] +#[cfg_attr(feature = "instrument", tracing::instrument(ret(level = "trace")))] pub(crate) fn is_display_name_ambiguous( display_name: &DisplayName, users_with_display_name: &BTreeSet, diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index 73067a8dc43..d7889f3f98b 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -36,7 +36,7 @@ use ruma::{ serde::Raw, time::Instant, }; -use tracing::{debug, instrument, warn}; +use tracing::{debug, warn}; use super::{ DependentQueuedRequest, DependentQueuedRequestKind, QueuedRequestKind, Result, RoomInfo, @@ -322,7 +322,7 @@ impl StateStore for MemoryStore { Ok(()) } - #[instrument(skip(self, changes))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, changes)))] async fn save_changes(&self, changes: &StateChanges) -> Result<()> { let now = Instant::now(); @@ -655,7 +655,7 @@ impl StateStore for MemoryStore { .collect()) } - #[instrument(skip(self, memberships))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, memberships)))] async fn get_user_ids( &self, room_id: &RoomId, diff --git a/crates/matrix-sdk-common/Cargo.toml b/crates/matrix-sdk-common/Cargo.toml index 92500766ada..2a5437d3b05 100644 --- a/crates/matrix-sdk-common/Cargo.toml +++ b/crates/matrix-sdk-common/Cargo.toml @@ -28,6 +28,9 @@ test-send-sync = [] # https://github.com/matrix-org/matrix-rust-sdk/issues/5397. experimental-encrypted-state-events = [] +# tokio-rs/tracing instrumentation +instrument = [] + [dependencies] eyeball-im.workspace = true futures-core.workspace = true diff --git a/crates/matrix-sdk-common/src/cross_process_lock.rs b/crates/matrix-sdk-common/src/cross_process_lock.rs index 483705d4719..7277fc44290 100644 --- a/crates/matrix-sdk-common/src/cross_process_lock.rs +++ b/crates/matrix-sdk-common/src/cross_process_lock.rs @@ -48,7 +48,9 @@ use std::{ }; use tokio::sync::Mutex; -use tracing::{debug, error, instrument, trace, warn}; +#[cfg(feature = "instrument")] +use tracing::instrument; +use tracing::{debug, error, trace, warn}; use crate::{ SendOutsideWasm, @@ -301,7 +303,7 @@ where /// /// The lock can be obtained but it can be dirty. In all cases, the renew /// task will run in the background. - #[instrument(skip(self), fields(?self.lock_key, ?self.config, ?self.generation))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(?self.lock_key, ?self.config, ?self.generation)))] pub async fn try_lock_once(&self) -> AcquireCrossProcessLockResult { // If it's not `MultiProcess`, this behaves as a no-op let CrossProcessLockConfig::MultiProcess { holder_name } = &self.config else { @@ -466,7 +468,7 @@ where /// reached a second time, the lock will stop attempting to get the lock /// and will return a timeout error upon locking. If not provided, /// will wait for [`MAX_BACKOFF_MS`]. - #[instrument(skip(self), fields(?self.lock_key, ?self.config))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(?self.lock_key, ?self.config)))] pub async fn spin_lock( &self, max_backoff: Option, diff --git a/crates/matrix-sdk-crypto/Cargo.toml b/crates/matrix-sdk-crypto/Cargo.toml index 9a64930fdf9..2cf816212ad 100644 --- a/crates/matrix-sdk-crypto/Cargo.toml +++ b/crates/matrix-sdk-crypto/Cargo.toml @@ -44,6 +44,9 @@ testing = ["matrix-sdk-test"] # https://github.com/matrix-org/matrix-spec-proposals/pull/4385 experimental-push-secrets = [] +# tokio-rs/tracing instrumentation +instrument = ["matrix-sdk-common/instrument"] + [dependencies] aes = { version = "0.8.4", default-features = false } aquamarine.workspace = true diff --git a/crates/matrix-sdk-crypto/src/backups/mod.rs b/crates/matrix-sdk-crypto/src/backups/mod.rs index 2aa0fd14f37..62df31b56f0 100644 --- a/crates/matrix-sdk-crypto/src/backups/mod.rs +++ b/crates/matrix-sdk-crypto/src/backups/mod.rs @@ -33,7 +33,7 @@ use ruma::{ TransactionId, api::client::backup::RoomKeyBackup, serde::Raw, }; use tokio::sync::RwLock; -use tracing::{debug, info, instrument, trace, warn}; +use tracing::{debug, info, trace, warn}; use crate::{ CryptoStoreError, Device, RoomKeyImportResult, SignatureError, @@ -404,7 +404,7 @@ impl BackupMachine { /// /// This will remove any pending backup request, remove the backup key and /// reset the backup state of each room key we have. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn disable_backup(&self) -> Result<(), CryptoStoreError> { debug!("Disabling key backup and resetting backup state for room keys"); diff --git a/crates/matrix-sdk-crypto/src/gossiping/machine.rs b/crates/matrix-sdk-crypto/src/gossiping/machine.rs index f6b8588891b..0c8fd19f877 100644 --- a/crates/matrix-sdk-crypto/src/gossiping/machine.rs +++ b/crates/matrix-sdk-crypto/src/gossiping/machine.rs @@ -40,7 +40,7 @@ use ruma::{ RequestAction, SecretName, ToDeviceSecretRequestEvent as SecretRequestEvent, }, }; -use tracing::{Span, debug, field::debug, info, instrument, trace, warn}; +use tracing::{Span, debug, field::debug, info, trace, warn}; use vodozemac::Curve25519PublicKey; use super::{GossipRequest, GossippedSecret, RequestEvent, RequestInfo, SecretInfo, WaitQueue}; @@ -1054,7 +1054,10 @@ impl GossipMachine { Ok(()) } - #[instrument(skip_all, fields(sender_key, sender = ?event.sender, request_id = ?event.content.request_id, secret_name))] + #[cfg_attr( + feature = "instrument", + tracing::instrument(skip_all, fields(sender_key, sender = ?event.sender, request_id = ?event.content.request_id, secret_name))) + ] pub async fn receive_secret_event( &self, cache: &StoreCache, diff --git a/crates/matrix-sdk-crypto/src/identities/manager.rs b/crates/matrix-sdk-crypto/src/identities/manager.rs index c93a2f14b1c..521daeace8d 100644 --- a/crates/matrix-sdk-crypto/src/identities/manager.rs +++ b/crates/matrix-sdk-crypto/src/identities/manager.rs @@ -27,7 +27,7 @@ use ruma::{ UserId, api::client::keys::get_keys::v3::Response as KeysQueryResponse, serde::Raw, }; use tokio::sync::Mutex; -use tracing::{Level, debug, enabled, info, instrument, trace, warn}; +use tracing::{Level, debug, enabled, info, trace, warn}; use crate::{ CryptoStoreError, LocalTrust, OwnUserIdentity, SignatureError, UserIdentity, @@ -667,7 +667,7 @@ impl IdentityManager { /// verification status of updated identity. /// * `key_set_info` - The identity info as returned by the `/keys/query` /// response. - #[instrument(skip_all, fields(user_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(user_id)))] async fn update_or_create_identity( &self, response: &KeysQueryResponse, @@ -1027,7 +1027,7 @@ impl IdentityManager { /// pending, reloads the device list and returns `Some(user_id, /// device_list)`. If no request was pending, returns `None`. #[allow(clippy::type_complexity)] - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_updated_keys_for_user<'a>( &self, timeout_duration: Duration, @@ -1086,7 +1086,7 @@ impl IdentityManager { /// Given a device, look for [`InboundGroupSession`]s whose sender data is /// in the given state, and update it. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn update_sender_data_for_sessions_for_device( &self, device: &DeviceData, @@ -1124,7 +1124,7 @@ impl IdentityManager { /// Update the sender data on the given inbound group session, using the /// given device data. - #[instrument(skip(self, device, session), fields(session_id = session.session_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, device, session), fields(session_id = session.session_id())))] async fn update_sender_data_for_session( &self, session: &mut InboundGroupSession, diff --git a/crates/matrix-sdk-crypto/src/machine/mod.rs b/crates/matrix-sdk-crypto/src/machine/mod.rs index 8240548311b..2ef57668780 100644 --- a/crates/matrix-sdk-crypto/src/machine/mod.rs +++ b/crates/matrix-sdk-crypto/src/machine/mod.rs @@ -304,7 +304,10 @@ impl OlmMachine { /// user/device IDs, e.g., to use the identity key as the device ID. /// /// [`CryptoStore`]: crate::store::CryptoStore - #[instrument(skip(store, custom_account), fields(ed25519_key, curve25519_key))] + #[cfg_attr( + feature = "instrument", + instrument(skip(store, custom_account), fields(ed25519_key, curve25519_key)) + )] pub async fn with_store( user_id: &UserId, device_id: &DeviceId, @@ -789,7 +792,7 @@ impl OlmMachine { /// this method between sync requests. /// /// [`mark_request_as_sent`]: #method.mark_request_as_sent - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn get_missing_sessions( &self, users: impl Iterator, @@ -939,7 +942,7 @@ impl OlmMachine { } /// Create a group session from a room key and add it to our crypto store. - #[instrument(skip_all, fields(algorithm = ?event.content.algorithm()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(algorithm = ?event.content.algorithm())))] async fn add_room_key( &self, sender_key: Curve25519PublicKey, @@ -962,7 +965,7 @@ impl OlmMachine { /// Handle a received, decrypted, `io.element.msc4268.room_key_bundle` /// to-device event. - #[instrument()] + #[cfg_attr(feature = "instrument", tracing::instrument())] async fn receive_room_key_bundle_data( &self, sender_key: Curve25519PublicKey, @@ -1529,7 +1532,10 @@ impl OlmMachine { /// /// If we can identify that this to-device event came from a dehydrated /// device, this method does not process it, and returns `None`. - #[instrument(skip_all, fields(sender, event_type, message_id))] + #[cfg_attr( + feature = "instrument", + instrument(skip_all, fields(sender, event_type, message_id)) + )] async fn receive_to_device_event( &self, transaction: &mut StoreTransaction, @@ -1724,7 +1730,7 @@ impl OlmMachine { /// # Returns /// /// A tuple of (decrypted to-device events, updated room keys). - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn receive_sync_changes( &self, sync_changes: EncryptionSyncChanges<'_>, @@ -2276,7 +2282,7 @@ impl OlmMachine { self.decrypt_room_event_inner(event, room_id, true, decryption_settings).await } - #[instrument(name = "decrypt_room_event", skip_all, fields(?room_id, event_id, origin_server_ts, sender, algorithm, session_id, message_index, sender_key))] + #[cfg_attr(feature = "instrument", tracing::instrument(name = "decrypt_room_event", skip_all, fields(?room_id, event_id, origin_server_ts, sender, algorithm, session_id, message_index, sender_key)))] async fn decrypt_room_event_inner( &self, event: &Raw, @@ -2558,7 +2564,10 @@ impl OlmMachine { /// /// * `event` - The event to get information for. /// * `room_id` - The ID of the room where the event was sent to. - #[instrument(skip(self, event), fields(event_id, sender, session_id))] + #[cfg_attr( + feature = "instrument", + instrument(skip(self, event), fields(event_id, sender, session_id)) + )] pub async fn get_room_event_encryption_info( &self, event: &Raw, @@ -2687,7 +2696,7 @@ impl OlmMachine { /// println!("{:?}", device); /// # }); /// ``` - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn get_device( &self, user_id: &UserId, @@ -2711,7 +2720,7 @@ impl OlmMachine { /// /// Returns a [`UserIdentity`] enum if one is found and the crypto store /// didn't throw an error. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn get_identity( &self, user_id: &UserId, @@ -2747,7 +2756,7 @@ impl OlmMachine { /// } /// # }); /// ``` - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn get_user_devices( &self, user_id: &UserId, diff --git a/crates/matrix-sdk-crypto/src/olm/account.rs b/crates/matrix-sdk-crypto/src/olm/account.rs index 9088c869477..a0bfeba974a 100644 --- a/crates/matrix-sdk-crypto/src/olm/account.rs +++ b/crates/matrix-sdk-crypto/src/olm/account.rs @@ -569,7 +569,7 @@ impl Account { /// /// Generally `Some` means that keys should be uploaded, while `None` means /// that keys should not be uploaded. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn generate_one_time_keys_if_needed(&mut self) -> Option { // Only generate one-time keys if there aren't any, otherwise the caller // might have failed to upload them the last time this method was @@ -1221,7 +1221,7 @@ impl Account { .await } - #[instrument(skip_all, fields(sender, sender_key = ?content.sender_key))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(sender, sender_key = ?content.sender_key)))] async fn decrypt_olm_v1( &mut self, store: &Store, @@ -1245,7 +1245,7 @@ impl Account { } } - #[instrument(skip_all, fields(algorithm = ?event.content.algorithm()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(algorithm = ?event.content.algorithm())))] pub(crate) async fn decrypt_to_device_event( &mut self, store: &Store, @@ -1415,7 +1415,10 @@ impl Account { /// Decrypt an Olm message, creating a new Olm session if necessary, and /// parse the result. - #[instrument(skip(self, store), fields(session, session_id))] + #[cfg_attr( + feature = "instrument", + tracing::instrument(skip(self, store), fields(session, session_id)) + )] async fn decrypt_and_parse_olm_message( &mut self, store: &Store, diff --git a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs index 9103821fc98..ef4c79623bd 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/mod.rs @@ -43,7 +43,7 @@ pub(crate) use share_strategy::split_devices_for_share_strategy; pub(crate) use share_strategy::{ CollectRecipientsResult, withheld_code_for_device_for_share_strategy, }; -use tracing::{Instrument, debug, error, info, instrument, trace, warn}; +use tracing::{Instrument, debug, error, info, trace, warn}; #[cfg(feature = "experimental-encrypted-state-events")] use crate::types::events::room::encrypted::RoomEncryptedEventContent; @@ -386,7 +386,7 @@ impl GroupSessionManager { /// Returns information indicating whether the session needs to be rotated /// and the list of users/devices that should receive or not the session /// (with withheld reason). - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn collect_session_recipients( &self, users: impl Iterator, @@ -678,7 +678,10 @@ impl GroupSessionManager { /// /// `encryption_settings` - The settings that should be used for /// the room key. - #[instrument(skip(self, users, encryption_settings), fields(session_id))] + #[cfg_attr( + feature = "instrument", + tracing::instrument(skip(self, users, encryption_settings), fields(session_id)) + )] pub async fn share_room_key( &self, room_id: &RoomId, @@ -821,7 +824,7 @@ impl GroupSessionManager { /// [`CollectStrategy::ErrorOnVerifiedUserProblem`] are "unsafe" in this /// respect,and are treated the same as /// [`CollectStrategy::IdentityBasedStrategy`]. - #[instrument(skip(self, bundle_data))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, bundle_data)))] pub async fn share_room_key_bundle_data( &self, user_id: &UserId, diff --git a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs index e0e2b1ee6f1..f2e85b93f1f 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/group_sessions/share_strategy.rs @@ -21,7 +21,7 @@ use itertools::{Either, Itertools}; use matrix_sdk_common::deserialized_responses::WithheldCode; use ruma::{DeviceId, OwnedDeviceId, OwnedUserId, UserId}; use serde::{Deserialize, Serialize}; -use tracing::{debug, instrument, trace}; +use tracing::{debug, trace}; use super::OutboundGroupSession; #[cfg(doc)] @@ -176,7 +176,7 @@ pub(crate) struct CollectRecipientsResult { /// Returns information indicating whether the session needs to be rotated /// and the list of users/devices that should receive or not the session /// (with withheld reason). -#[instrument(skip_all)] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn collect_session_recipients( store: &Store, users: impl Iterator, diff --git a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs index d27b9bc4793..e4914b46d83 100644 --- a/crates/matrix-sdk-crypto/src/session_manager/sessions.rs +++ b/crates/matrix-sdk-crypto/src/session_manager/sessions.rs @@ -28,7 +28,7 @@ use ruma::{ assign, events::dummy::ToDeviceDummyEventContent, }; -use tracing::{debug, error, info, instrument, warn}; +use tracing::{debug, error, info, warn}; use vodozemac::Curve25519PublicKey; use crate::{ @@ -424,7 +424,7 @@ impl SessionManager { /// needed to couple the response with the sent out request. /// /// * `response` - The response containing the claimed one-time keys. - #[instrument(skip(self, response))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, response)))] pub async fn receive_keys_claim_response( &self, request_id: &TransactionId, diff --git a/crates/matrix-sdk-crypto/src/store/caches.rs b/crates/matrix-sdk-crypto/src/store/caches.rs index 228821d1b47..5293bd1d0b9 100644 --- a/crates/matrix-sdk-crypto/src/store/caches.rs +++ b/crates/matrix-sdk-crypto/src/store/caches.rs @@ -31,7 +31,7 @@ use matrix_sdk_common::locks::RwLock as StdRwLock; use ruma::{DeviceId, OwnedDeviceId, OwnedUserId, UserId}; use serde::{Deserialize, Serialize}; use tokio::sync::{Mutex, MutexGuard, OwnedRwLockReadGuard, RwLock}; -use tracing::{Span, field::display, instrument, trace}; +use tracing::{Span, field::display, trace}; use super::{CryptoStoreError, CryptoStoreWrapper}; use crate::{Account, identities::DeviceData, olm::Session}; @@ -234,7 +234,10 @@ impl UsersForKeyQuery { /// user, it is removed from the list of those needing an update. /// /// Returns true if the user is now up-to-date, else false - #[instrument(level = "trace", skip(self), fields(invalidation_sequence))] + #[cfg_attr( + feature = "instrument", + instrument(level = "trace", skip(self), fields(invalidation_sequence)) + )] pub(super) fn maybe_remove_user( &mut self, user: &UserId, diff --git a/crates/matrix-sdk-crypto/src/store/mod.rs b/crates/matrix-sdk-crypto/src/store/mod.rs index 9460d27d07f..f8700180ba1 100644 --- a/crates/matrix-sdk-crypto/src/store/mod.rs +++ b/crates/matrix-sdk-crypto/src/store/mod.rs @@ -59,7 +59,7 @@ use serde::{Serialize, de::DeserializeOwned}; use thiserror::Error; use tokio::sync::{Mutex, Notify, OwnedRwLockWriteGuard, RwLock}; use tokio_stream::wrappers::errors::BroadcastStreamRecvError; -use tracing::{info, instrument, trace, warn}; +use tracing::{info, trace, warn}; use types::{RoomKeyBundleInfo, StoredRoomKeyBundleData}; use vodozemac::{Curve25519PublicKey, megolm::SessionOrdering}; @@ -1674,7 +1674,7 @@ impl Store { /// * `bundle` - The decrypted and deserialized bundle itself. /// /// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268 - #[instrument(skip(self, bundle, progress_listener), fields(bundle_size = bundle.room_keys.len(), sender_data))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, bundle, progress_listener), fields(bundle_size = bundle.room_keys.len(), sender_data)))] pub async fn receive_room_key_bundle( &self, bundle_info: &StoredRoomKeyBundleData, diff --git a/crates/matrix-sdk-crypto/src/verification/machine.rs b/crates/matrix-sdk-crypto/src/verification/machine.rs index 7910563ae3c..9bbba2dfab5 100644 --- a/crates/matrix-sdk-crypto/src/verification/machine.rs +++ b/crates/matrix-sdk-crypto/src/verification/machine.rs @@ -26,7 +26,7 @@ use ruma::{ uint, }; use tokio::sync::Mutex; -use tracing::{Span, debug, info, instrument, trace, warn}; +use tracing::{Span, debug, info, trace, warn}; use super::{ FlowId, Verification, VerificationResult, VerificationStore, @@ -300,7 +300,7 @@ impl VerificationMachine { Ok(()) } - #[instrument(skip_all, fields(flow_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(flow_id)))] pub async fn receive_any_event( &self, event: impl Into>, diff --git a/crates/matrix-sdk-indexeddb/Cargo.toml b/crates/matrix-sdk-indexeddb/Cargo.toml index a14f2784d71..59986c97a9e 100644 --- a/crates/matrix-sdk-indexeddb/Cargo.toml +++ b/crates/matrix-sdk-indexeddb/Cargo.toml @@ -29,6 +29,8 @@ experimental-encrypted-state-events = [ experimental-push-secrets = [ "matrix-sdk-crypto?/experimental-push-secrets" ] +# tokio-rs/tracing instrumentation +instrument = ["matrix-sdk-base?/instrument", "matrix-sdk-crypto?/instrument"] [dependencies] async-trait.workspace = true diff --git a/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs b/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs index 6056566cf43..61b91cecfe1 100644 --- a/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/event_cache_store/mod.rs @@ -32,7 +32,7 @@ use matrix_sdk_base::{ use ruma::{ EventId, MilliSecondsSinceUnixEpoch, OwnedEventId, RoomId, events::relation::RelationType, }; -use tracing::{error, instrument, trace}; +use tracing::{error, trace}; use web_sys::IdbTransactionMode; use crate::{ @@ -101,7 +101,7 @@ impl IndexeddbEventCacheStore { impl EventCacheStore for IndexeddbEventCacheStore { type Error = IndexeddbEventCacheStoreError; - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn try_take_leased_lock( &self, lease_duration_ms: u32, @@ -158,7 +158,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { }) } - #[instrument(skip(self, updates))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, updates)))] async fn handle_linked_chunk_updates( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -273,7 +273,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { Ok(()) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_all_chunks( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -298,7 +298,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { Ok(raw_chunks) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_all_chunks_metadata( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -336,7 +336,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { Ok(raw_chunks) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_last_chunk( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -392,7 +392,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { } } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_previous_chunk( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -415,7 +415,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { } } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn clear_all_linked_chunks(&self) -> Result<(), IndexeddbEventCacheStoreError> { let _timer = timer!("method"); @@ -430,7 +430,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { Ok(()) } - #[instrument(skip(self, events))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, events)))] async fn filter_duplicated_events( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -454,7 +454,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { Ok(duplicated) } - #[instrument(skip(self, event_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event_id)))] async fn find_event( &self, room_id: &RoomId, @@ -470,7 +470,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { .map_err(Into::into) } - #[instrument(skip(self, event_id, filters))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event_id, filters)))] async fn find_event_relations( &self, room_id: &RoomId, @@ -537,7 +537,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { .collect()) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_room_events( &self, room_id: &RoomId, @@ -574,7 +574,7 @@ impl EventCacheStore for IndexeddbEventCacheStore { .map_err(Into::into) } - #[instrument(skip(self, event))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event)))] async fn save_event( &self, room_id: &RoomId, diff --git a/crates/matrix-sdk-indexeddb/src/media_store/mod.rs b/crates/matrix-sdk-indexeddb/src/media_store/mod.rs index c9d51a59765..bb8cd3f3c98 100644 --- a/crates/matrix-sdk-indexeddb/src/media_store/mod.rs +++ b/crates/matrix-sdk-indexeddb/src/media_store/mod.rs @@ -46,7 +46,6 @@ use matrix_sdk_base::{ timer, }; use ruma::{MilliSecondsSinceUnixEpoch, MxcUri, time::SystemTime}; -use tracing::instrument; use crate::{ media_store::{ @@ -104,7 +103,7 @@ impl IndexeddbMediaStore { impl MediaStore for IndexeddbMediaStore { type Error = IndexeddbMediaStoreError; - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn try_take_leased_lock( &self, lease_duration_ms: u32, @@ -160,7 +159,7 @@ impl MediaStore for IndexeddbMediaStore { }) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn add_media_content( &self, request: &MediaRequestParameters, @@ -171,7 +170,7 @@ impl MediaStore for IndexeddbMediaStore { self.media_service.add_media_content(self, request, content, ignore_policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn replace_media_key( &self, from: &MediaRequestParameters, @@ -191,7 +190,7 @@ impl MediaStore for IndexeddbMediaStore { Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn get_media_content( &self, request: &MediaRequestParameters, @@ -200,7 +199,7 @@ impl MediaStore for IndexeddbMediaStore { self.media_service.get_media_content(self, request).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn remove_media_content( &self, request: &MediaRequestParameters, @@ -215,7 +214,7 @@ impl MediaStore for IndexeddbMediaStore { transaction.commit().await.map_err(Into::into) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_media_content_for_uri( &self, uri: &MxcUri, @@ -224,7 +223,7 @@ impl MediaStore for IndexeddbMediaStore { self.media_service.get_media_content_for_uri(self, uri).await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn remove_media_content_for_uri( &self, uri: &MxcUri, @@ -239,7 +238,7 @@ impl MediaStore for IndexeddbMediaStore { transaction.commit().await.map_err(Into::into) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_media_retention_policy( &self, policy: MediaRetentionPolicy, @@ -248,13 +247,13 @@ impl MediaStore for IndexeddbMediaStore { self.media_service.set_media_retention_policy(self, policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn media_retention_policy(&self) -> MediaRetentionPolicy { let _timer = timer!("method"); self.media_service.media_retention_policy() } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_ignore_media_retention_policy( &self, request: &MediaRequestParameters, @@ -264,7 +263,7 @@ impl MediaStore for IndexeddbMediaStore { self.media_service.set_ignore_media_retention_policy(self, request, ignore_policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn clean(&self) -> Result<(), IndexeddbMediaStoreError> { let _timer = timer!("method"); self.media_service.clean(self).await @@ -284,7 +283,7 @@ impl MediaStore for IndexeddbMediaStore { impl MediaStoreInner for IndexeddbMediaStore { type Error = IndexeddbMediaStoreError; - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn media_retention_policy_inner( &self, ) -> Result, IndexeddbMediaStoreError> { @@ -295,7 +294,7 @@ impl MediaStoreInner for IndexeddbMediaStore { .map_err(Into::into) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_media_retention_policy_inner( &self, policy: MediaRetentionPolicy, @@ -308,7 +307,7 @@ impl MediaStoreInner for IndexeddbMediaStore { transaction.commit().await.map_err(Into::into) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn add_media_content_inner( &self, request: &MediaRequestParameters, @@ -335,7 +334,7 @@ impl MediaStoreInner for IndexeddbMediaStore { transaction.commit().await.map_err(Into::into) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_ignore_media_retention_policy_inner( &self, request: &MediaRequestParameters, @@ -355,7 +354,7 @@ impl MediaStoreInner for IndexeddbMediaStore { Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn get_media_content_inner( &self, request: &MediaRequestParameters, @@ -372,7 +371,7 @@ impl MediaStoreInner for IndexeddbMediaStore { Ok(media.map(|m| m.content)) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn get_media_content_for_uri_inner( &self, uri: &MxcUri, @@ -389,7 +388,7 @@ impl MediaStoreInner for IndexeddbMediaStore { Ok(media.map(|m| m.content)) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn clean_inner( &self, policy: MediaRetentionPolicy, @@ -459,7 +458,7 @@ impl MediaStoreInner for IndexeddbMediaStore { transaction.commit().await.map_err(Into::into) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn last_media_cleanup_time_inner( &self, ) -> Result, IndexeddbMediaStoreError> { diff --git a/crates/matrix-sdk-sqlite/Cargo.toml b/crates/matrix-sdk-sqlite/Cargo.toml index e11cf2ad873..b6cae1ff1b1 100644 --- a/crates/matrix-sdk-sqlite/Cargo.toml +++ b/crates/matrix-sdk-sqlite/Cargo.toml @@ -26,6 +26,9 @@ experimental-push-secrets = [ "matrix-sdk-crypto?/experimental-push-secrets" ] +# tokio-rs/tracing instrumentation +instrument = [] + [dependencies] as_variant.workspace = true async-trait.workspace = true diff --git a/crates/matrix-sdk-sqlite/src/crypto_store.rs b/crates/matrix-sdk-sqlite/src/crypto_store.rs index 35308b2b5a2..14fea1d12b1 100644 --- a/crates/matrix-sdk-sqlite/src/crypto_store.rs +++ b/crates/matrix-sdk-sqlite/src/crypto_store.rs @@ -47,7 +47,7 @@ use tokio::{ fs, sync::{Mutex, OwnedMutexGuard}, }; -use tracing::{debug, instrument, warn}; +use tracing::{debug, warn}; use vodozemac::Curve25519PublicKey; use zeroize::Zeroizing; @@ -208,13 +208,13 @@ impl SqliteCryptoStore { } /// Acquire a connection for executing read operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn read(&self) -> Result { Ok(self.pool.get().await?) } /// Acquire a connection for executing write operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn write(&self) -> OwnedMutexGuard { self.write_connection.clone().lock_owned().await } @@ -1310,7 +1310,7 @@ impl CryptoStore for SqliteCryptoStore { if sessions.is_empty() { Ok(None) } else { Ok(Some(sessions)) } } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_inbound_group_session( &self, room_id: &RoomId, @@ -1755,7 +1755,7 @@ impl CryptoStore for SqliteCryptoStore { Ok(()) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn try_take_leased_lock( &self, lease_duration_ms: u32, diff --git a/crates/matrix-sdk-sqlite/src/event_cache_store.rs b/crates/matrix-sdk-sqlite/src/event_cache_store.rs index 794f9323e41..f518cb37ac5 100644 --- a/crates/matrix-sdk-sqlite/src/event_cache_store.rs +++ b/crates/matrix-sdk-sqlite/src/event_cache_store.rs @@ -41,7 +41,7 @@ use tokio::{ fs, sync::{Mutex, OwnedMutexGuard}, }; -use tracing::{debug, error, instrument, trace}; +use tracing::{debug, error, trace}; use crate::{ OpenStoreError, Secret, SqliteStoreConfig, @@ -117,7 +117,7 @@ impl SqliteEventCacheStore { } /// Open the SQLite-based event cache store with the config open config. - #[instrument(skip(config), fields(path = ?config.path))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(config), fields(path = ?config.path)))] pub async fn open_with_config(config: SqliteStoreConfig) -> Result { debug!(?config); @@ -161,7 +161,7 @@ impl SqliteEventCacheStore { } /// Acquire a connection for executing read operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn read(&self) -> Result { let connection = self.pool.get().await?; @@ -175,7 +175,7 @@ impl SqliteEventCacheStore { } /// Acquire a connection for executing write operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn write(&self) -> Result> { let connection = self.write_connection.clone().lock_owned().await; @@ -512,7 +512,7 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> { impl EventCacheStore for SqliteEventCacheStore { type Error = Error; - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn try_take_leased_lock( &self, lease_duration_ms: u32, @@ -558,7 +558,7 @@ impl EventCacheStore for SqliteEventCacheStore { Ok(generation) } - #[instrument(skip(self, updates))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, updates)))] async fn handle_linked_chunk_updates( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -905,7 +905,7 @@ impl EventCacheStore for SqliteEventCacheStore { Ok(()) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_all_chunks( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -949,7 +949,7 @@ impl EventCacheStore for SqliteEventCacheStore { Ok(result) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_all_chunks_metadata( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -1047,7 +1047,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_last_chunk( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -1142,7 +1142,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn load_previous_chunk( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -1196,7 +1196,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn clear_all_linked_chunks(&self) -> Result<(), Self::Error> { let _timer = timer!("method"); @@ -1213,7 +1213,7 @@ impl EventCacheStore for SqliteEventCacheStore { Ok(()) } - #[instrument(skip(self, events))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, events)))] async fn filter_duplicated_events( &self, linked_chunk_id: LinkedChunkId<'_>, @@ -1295,7 +1295,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self, event_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event_id)))] async fn find_event( &self, room_id: &RoomId, @@ -1327,7 +1327,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self, event_id, filters))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event_id, filters)))] async fn find_event_relations( &self, room_id: &RoomId, @@ -1360,7 +1360,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_room_events( &self, room_id: &RoomId, @@ -1414,7 +1414,7 @@ impl EventCacheStore for SqliteEventCacheStore { .await } - #[instrument(skip(self, event))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, event)))] async fn save_event(&self, room_id: &RoomId, event: Event) -> Result<(), Self::Error> { let _timer = timer!("method"); diff --git a/crates/matrix-sdk-sqlite/src/lib.rs b/crates/matrix-sdk-sqlite/src/lib.rs index 03321f2589c..ae84e1d4397 100644 --- a/crates/matrix-sdk-sqlite/src/lib.rs +++ b/crates/matrix-sdk-sqlite/src/lib.rs @@ -16,6 +16,8 @@ not(any(feature = "state-store", feature = "crypto-store", feature = "event-cache")), allow(dead_code, unused_imports) )] +// Increase recursion limit when using instrumentation: https://github.com/rust-lang/rust/issues/152942 +#![cfg_attr(not(feature = "instrument"), recursion_limit = "256")] mod connection; #[cfg(feature = "crypto-store")] diff --git a/crates/matrix-sdk-sqlite/src/media_store.rs b/crates/matrix-sdk-sqlite/src/media_store.rs index a1c364df5c7..13ee5b5c84a 100644 --- a/crates/matrix-sdk-sqlite/src/media_store.rs +++ b/crates/matrix-sdk-sqlite/src/media_store.rs @@ -35,7 +35,7 @@ use tokio::{ fs, sync::{Mutex, OwnedMutexGuard}, }; -use tracing::{debug, instrument}; +use tracing::debug; use crate::{ OpenStoreError, Secret, SqliteStoreConfig, @@ -109,7 +109,7 @@ impl SqliteMediaStore { } /// Open the SQLite-based media store with the config open config. - #[instrument(skip(config), fields(path = ?config.path))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(config), fields(path = ?config.path)))] pub async fn open_with_config(config: SqliteStoreConfig) -> Result { debug!(?config); @@ -158,7 +158,7 @@ impl SqliteMediaStore { } // Acquire a connection for executing read operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn read(&self) -> Result { let connection = self.pool.get().await?; @@ -172,7 +172,7 @@ impl SqliteMediaStore { } // Acquire a connection for executing write operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn write(&self) -> Result> { let connection = self.write_connection.clone().lock_owned().await; @@ -229,7 +229,7 @@ async fn run_migrations(conn: &SqliteAsyncConn, version: u8) -> Result<()> { impl MediaStore for SqliteMediaStore { type Error = Error; - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn try_take_leased_lock( &self, lease_duration_ms: u32, @@ -286,7 +286,7 @@ impl MediaStore for SqliteMediaStore { self.media_service.add_media_content(self, request, content, ignore_policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn replace_media_key( &self, from: &MediaRequestParameters, @@ -310,14 +310,14 @@ impl MediaStore for SqliteMediaStore { Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn get_media_content(&self, request: &MediaRequestParameters) -> Result>> { let _timer = timer!("method"); self.media_service.get_media_content(self, request).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn remove_media_content(&self, request: &MediaRequestParameters) -> Result<()> { let _timer = timer!("method"); @@ -330,7 +330,7 @@ impl MediaStore for SqliteMediaStore { Ok(()) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn get_media_content_for_uri( &self, uri: &MxcUri, @@ -340,7 +340,7 @@ impl MediaStore for SqliteMediaStore { self.media_service.get_media_content_for_uri(self, uri).await } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn remove_media_content_for_uri(&self, uri: &MxcUri) -> Result<()> { let _timer = timer!("method"); @@ -352,7 +352,7 @@ impl MediaStore for SqliteMediaStore { Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_media_retention_policy( &self, policy: MediaRetentionPolicy, @@ -362,14 +362,14 @@ impl MediaStore for SqliteMediaStore { self.media_service.set_media_retention_policy(self, policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn media_retention_policy(&self) -> MediaRetentionPolicy { let _timer = timer!("method"); self.media_service.media_retention_policy() } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn set_ignore_media_retention_policy( &self, request: &MediaRequestParameters, @@ -380,7 +380,7 @@ impl MediaStore for SqliteMediaStore { self.media_service.set_ignore_media_retention_policy(self, request, ignore_policy).await } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn clean(&self) -> Result<(), Self::Error> { let _timer = timer!("method"); diff --git a/crates/matrix-sdk-sqlite/src/state_store.rs b/crates/matrix-sdk-sqlite/src/state_store.rs index e378742d512..c12caec0764 100644 --- a/crates/matrix-sdk-sqlite/src/state_store.rs +++ b/crates/matrix-sdk-sqlite/src/state_store.rs @@ -41,7 +41,7 @@ use tokio::{ fs, sync::{Mutex, OwnedMutexGuard}, }; -use tracing::{debug, instrument, warn}; +use tracing::{debug, warn}; use crate::{ OpenStoreError, Secret, SqliteStoreConfig, @@ -534,13 +534,13 @@ impl SqliteStateStore { } /// Acquire a connection for executing read operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn read(&self) -> Result { Ok(self.pool.get().await?) } /// Acquire a connection for executing write operations. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn write(&self) -> OwnedMutexGuard { self.write_connection.clone().lock_owned().await } diff --git a/crates/matrix-sdk-ui/Cargo.toml b/crates/matrix-sdk-ui/Cargo.toml index 76257cad6ec..e49bb88e9b7 100644 --- a/crates/matrix-sdk-ui/Cargo.toml +++ b/crates/matrix-sdk-ui/Cargo.toml @@ -28,6 +28,9 @@ experimental-encrypted-state-events = [ "ruma/unstable-msc4362" ] +# tokio-rs/tracing instrumentation +instrument = [] + [dependencies] as_variant.workspace = true async-rx = { workspace = true, features = ["alloc"] } diff --git a/crates/matrix-sdk-ui/src/encryption_sync_service.rs b/crates/matrix-sdk-ui/src/encryption_sync_service.rs index 27b33d18d15..9bade4364ed 100644 --- a/crates/matrix-sdk-ui/src/encryption_sync_service.rs +++ b/crates/matrix-sdk-ui/src/encryption_sync_service.rs @@ -35,7 +35,7 @@ use matrix_sdk::{Client, LEASE_DURATION_MS, SlidingSync, sleep::sleep}; use matrix_sdk_common::cross_process_lock::CrossProcessLockConfig; use ruma::{api::client::sync::sync_events::v5 as http, assign}; use tokio::sync::OwnedMutexGuard; -use tracing::{debug, instrument, trace}; +use tracing::{debug, trace}; /// Unit type representing a permit to *use* an [`EncryptionSyncService`]. /// @@ -122,7 +122,7 @@ impl EncryptionSyncService { /// Note: the [`EncryptionSyncPermit`] parameter ensures that there's at /// most one encryption sync running at any time. See its documentation /// for more details. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn run_fixed_iterations( self, num_iterations: u8, @@ -257,7 +257,7 @@ impl EncryptionSyncService { /// Helper function for `sync`. Take the cross-process store lock, and call /// `sync.next()` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn next_sync_with_lock( &self, sync: &mut Pin<&mut impl Stream>, diff --git a/crates/matrix-sdk-ui/src/notification_client.rs b/crates/matrix-sdk-ui/src/notification_client.rs index 67142f6ac4c..1f9fefb6751 100644 --- a/crates/matrix-sdk-ui/src/notification_client.rs +++ b/crates/matrix-sdk-ui/src/notification_client.rs @@ -47,7 +47,7 @@ use ruma::{ }; use thiserror::Error; use tokio::sync::Mutex as AsyncMutex; -use tracing::{debug, info, instrument, trace, warn}; +use tracing::{debug, info, trace, warn}; use crate::{ DEFAULT_SANITIZER_MODE, @@ -151,7 +151,7 @@ impl NotificationClient { /// /// An error result means that we couldn't resolve the notification; in that /// case, a dummy notification may be displayed instead. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn get_notification( &self, room_id: &RoomId, @@ -216,7 +216,7 @@ impl NotificationClient { /// /// Otherwise, if the event was not encrypted, or couldn't be decrypted /// (without causing a fatal error), will return `Ok(None)`. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn retry_decryption( &self, room: &Room, @@ -374,7 +374,7 @@ impl NotificationClient { /// match the current user and are invites), and if the SDK concludes the /// room was in the invited state, and we didn't find the event by id, /// *then* we'll use that stripped room member event. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn try_sliding_sync( &self, requests: &[NotificationItemsRequest], diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index 4c64ed3556f..41c4e3dc9a6 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -43,7 +43,7 @@ use tokio::sync::{ Mutex as AsyncMutex, OwnedMutexGuard, mpsc::{Receiver, Sender}, }; -use tracing::{Instrument, Level, Span, error, info, instrument, trace, warn}; +use tracing::{Instrument, Level, Span, error, info, trace, warn}; use crate::{ encryption_sync_service::{self, EncryptionSyncPermit, EncryptionSyncService}, @@ -651,7 +651,7 @@ impl SyncService { /// This must be called when the app goes into the background. It's better /// to call this API when the application exits, although not strictly /// necessary. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn stop(&self) { let mut inner = self.inner.lock().await; @@ -671,7 +671,7 @@ impl SyncService { /// This ensures that the sync service is stopped before expiring both /// sessions. It should be used sparingly, as it will cause a restart of /// the sessions on the server as well. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn expire_sessions(&self) { // First, stop the sync service if it was running; it's a no-op if it was // already stopped. diff --git a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs index 717e5c5f45e..f7d04e856c0 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/mod.rs @@ -54,9 +54,7 @@ use ruma::{ serde::Raw, }; use tokio::sync::{RwLock, RwLockWriteGuard, broadcast}; -use tracing::{ - Instrument as _, Span, debug, error, field::debug, info, info_span, instrument, trace, warn, -}; +use tracing::{Instrument as _, Span, debug, error, field::debug, info, info_span, trace, warn}; pub(super) use self::{ metadata::{RelativePosition, TimelineMetadata}, @@ -486,7 +484,7 @@ impl TimelineController

{ /// Toggle a reaction locally. /// /// Returns true if the reaction was added, false if it was removed. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn toggle_reaction_local( &self, item_id: &TimelineEventItemId, @@ -740,7 +738,7 @@ impl TimelineController

{ } /// Creates the local echo for an event we're sending. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn handle_local_event( &self, txn_id: OwnedTransactionId, @@ -762,7 +760,7 @@ impl TimelineController

{ /// /// If the corresponding local timeline item is missing, a warning is /// raised. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub(super) async fn update_event_send_state( &self, txn_id: &TransactionId, @@ -1170,7 +1168,7 @@ impl TimelineController

{ } /// Adds a reaction (local echo) to a local echo. - #[instrument(skip(self, send_handle))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, send_handle)))] async fn handle_local_reaction( &self, reaction_key: String, @@ -1519,7 +1517,7 @@ impl TimelineController { /// Given an event identifier, will fetch the details for the event it's /// replying to, if applicable. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub(super) async fn fetch_in_reply_to_details(&self, event_id: &EventId) -> Result<(), Error> { let state_guard = self.state.write().await; let (index, item) = rfind_event_by_id(&state_guard.items, event_id) @@ -1749,7 +1747,7 @@ impl TimelineController { .next() } - #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = ?self.room().room_id())))] pub(super) async fn retry_event_decryption(&self, session_ids: Option>) { let (utds, decrypted) = self.compute_redecryption_candidates().await; diff --git a/crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs b/crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs index 347dcbe3a3e..e458b96ce02 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/read_receipts.rs @@ -22,7 +22,7 @@ use ruma::{ }; use tokio::sync::watch; use tokio_stream::wrappers::WatchStream; -use tracing::{debug, error, instrument, trace, warn}; +use tracing::{debug, error, trace, warn}; use super::{ AllRemoteEvents, ObservableItemsTransaction, RelativePosition, RoomDataProvider, @@ -93,7 +93,7 @@ impl ReadReceipts { /// /// Currently this method only works reliably if the timeline was started /// from the end of the timeline. - #[instrument(skip_all, fields(user_id = %new_receipt.user_id, event_id = %new_receipt.event_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(user_id = %new_receipt.user_id, event_id = %new_receipt.event_id)))] fn maybe_update_read_receipt( &mut self, new_receipt: FullReceipt<'_>, @@ -281,7 +281,7 @@ impl ReadReceipts { /// /// This includes all the receipts on the event as well as all the receipts /// on the following events that are filtered out (not visible). - #[instrument(skip(self, timeline_items, at_end))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, timeline_items, at_end)))] pub(super) fn compute_event_receipts( &self, event_id: &EventId, @@ -396,7 +396,7 @@ struct ReadReceiptTimelineUpdate { impl ReadReceiptTimelineUpdate { /// Remove the old receipt from the corresponding timeline item. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn remove_old_receipt(&mut self, items: &mut ObservableItemsTransaction<'_>, user_id: &UserId) { let Some(event_id) = &self.old_event_id else { // Nothing to do. @@ -444,7 +444,7 @@ impl ReadReceiptTimelineUpdate { } /// Add the new receipt to the corresponding timeline item. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn add_new_receipt( self, items: &mut ObservableItemsTransaction<'_>, @@ -717,7 +717,7 @@ impl TimelineStateTransaction<'_, P> { /// Update the read receipts on the event with the given event ID and the /// previous visible event because of a visibility change. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub(super) fn maybe_update_read_receipts_of_prev_event(&mut self, event_id: &EventId) { // Find the previous visible event, if there is one. let Some(prev_event_meta) = self diff --git a/crates/matrix-sdk-ui/src/timeline/controller/state.rs b/crates/matrix-sdk-ui/src/timeline/controller/state.rs index 5a4a41908b2..5baa26d0552 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/state.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/state.rs @@ -24,7 +24,7 @@ use ruma::{ room_version_rules::RoomVersionRules, serde::Raw, }; -use tracing::{instrument, trace, warn}; +use tracing::{trace, warn}; use super::{ super::{ @@ -116,7 +116,7 @@ impl TimelineState

{ txn.commit(); } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn handle_ephemeral_events( &mut self, events: Vec>, @@ -148,7 +148,7 @@ impl TimelineState

{ /// Adds a local echo (for an event) to the timeline. #[allow(clippy::too_many_arguments)] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn handle_local_event( &mut self, own_user_id: OwnedUserId, diff --git a/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs b/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs index ef9b8596d82..3fcc432fe81 100644 --- a/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs +++ b/crates/matrix-sdk-ui/src/timeline/controller/state_transaction.rs @@ -29,7 +29,7 @@ use ruma::{ push::Action, serde::Raw, }; -use tracing::{debug, instrument, trace, warn}; +use tracing::{debug, trace, warn}; use super::{ super::{ @@ -676,7 +676,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> { // Attempt to load a thread's latest reply as an embedded timeline item, either // using the event cache or the storage. - #[instrument(skip(self, room_data_provider))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, room_data_provider)))] async fn fetch_latest_thread_reply( &mut self, event_id: &EventId, @@ -1034,7 +1034,7 @@ impl<'a, P: RoomDataProvider> TimelineStateTransaction<'a, P> { debug!(remaining_items = self.items.len(), "Timeline cleared"); } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) fn set_fully_read_event(&mut self, fully_read_event_id: OwnedEventId) { // A similar event has been handled already. We can ignore it. if self.meta.fully_read_event.as_ref().is_some_and(|id| *id == fully_read_event_id) { diff --git a/crates/matrix-sdk-ui/src/timeline/date_dividers.rs b/crates/matrix-sdk-ui/src/timeline/date_dividers.rs index 6d7b4d8420c..62e1c043867 100644 --- a/crates/matrix-sdk-ui/src/timeline/date_dividers.rs +++ b/crates/matrix-sdk-ui/src/timeline/date_dividers.rs @@ -19,7 +19,7 @@ use std::{fmt::Display, sync::Arc}; use chrono::{Datelike, Local, TimeZone}; use ruma::MilliSecondsSinceUnixEpoch; -use tracing::{Level, error, event_enabled, instrument, trace, warn}; +use tracing::{Level, error, event_enabled, trace}; use super::{ DateDividerMode, TimelineItem, TimelineItemKind, VirtualTimelineItem, @@ -107,7 +107,7 @@ impl DateDividerAdjuster { /// Ensures that date separators are properly inserted/removed when needs /// be. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn run(&mut self, items: &mut ObservableItemsTransaction<'_>, meta: &mut TimelineMetadata) { // We're going to record vector operations like inserting, replacing and // removing date dividers. Since we may remove or insert new items, diff --git a/crates/matrix-sdk-ui/src/timeline/event_handler.rs b/crates/matrix-sdk-ui/src/timeline/event_handler.rs index 9a1e5f4e116..1f472020b93 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_handler.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_handler.rs @@ -576,7 +576,10 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { /// /// `raw_event` is only needed to determine the cause of any UTDs, /// so if we know this is not a UTD it can be None. - #[instrument(skip_all, fields(txn_id, event_id, position))] + #[cfg_attr( + feature = "instrument", + tracing::instrument(skip_all, fields(txn_id, event_id, position)) + )] pub(super) async fn handle_event( mut self, date_divider_adjuster: &mut DateDividerAdjuster, @@ -660,7 +663,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { added_item } - #[instrument(skip(self, edit_kind))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, edit_kind)))] fn handle_edit(&mut self, edited_event_id: OwnedEventId, edit_kind: PendingEditKind) { let target = TimelineEventItemId::EventId(edited_event_id.clone()); @@ -699,7 +702,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { /// /// Reactions to local events are applied in /// [`crate::timeline::TimelineController::handle_local_echo`]. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] fn handle_reaction(&mut self, relates_to: OwnedEventId, reaction_key: String) { let target = TimelineEventItemId::EventId(relates_to); @@ -839,7 +842,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { /// /// This assumes the redacted event was present in the timeline in the first /// place; it will warn if the redacted event has not been found. - #[instrument(skip_all, fields(redacts_event_id = ?redacted))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(redacts_event_id = ?redacted)))] fn handle_redaction(&mut self, redacted: OwnedEventId) { // TODO: Apply local redaction of PollResponse and PollEnd events. // https://github.com/matrix-org/matrix-rust-sdk/pull/2381#issuecomment-1689647825 @@ -885,7 +888,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { /// etc.). /// /// Returns true if it's succeeded. - #[instrument(skip_all, fields(redacts = ?aggregation_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(redacts = ?aggregation_id)))] fn handle_aggregation_redaction(&mut self, aggregation_id: OwnedEventId) -> bool { let aggregation_id = TimelineEventItemId::EventId(aggregation_id); diff --git a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs index 2f299fbf42a..b7259cce9be 100644 --- a/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs +++ b/crates/matrix-sdk-ui/src/timeline/event_item/content/reply.rs @@ -17,7 +17,7 @@ use std::sync::Arc; use imbl::Vector; use matrix_sdk::deserialized_responses::TimelineEvent; use ruma::{MilliSecondsSinceUnixEpoch, OwnedEventId, OwnedUserId}; -use tracing::{debug, instrument, warn}; +use tracing::{debug, warn}; use super::TimelineItemContent; use crate::timeline::{ @@ -90,7 +90,7 @@ impl EmbeddedEvent { } } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(in crate::timeline) async fn try_from_timeline_event( timeline_event: TimelineEvent, room_data_provider: &P, diff --git a/crates/matrix-sdk-ui/src/timeline/mod.rs b/crates/matrix-sdk-ui/src/timeline/mod.rs index 53456f7f37d..284f563c2a2 100644 --- a/crates/matrix-sdk-ui/src/timeline/mod.rs +++ b/crates/matrix-sdk-ui/src/timeline/mod.rs @@ -56,7 +56,7 @@ use ruma::{ }; use subscriber::TimelineWithDropHandle; use thiserror::Error; -use tracing::{instrument, trace, warn}; +use tracing::trace; use self::{ algorithms::rfind_event_by_id, controller::TimelineController, futures::SendAttachment, @@ -327,7 +327,7 @@ impl Timeline { /// # Arguments /// /// * `content` - The content of the message event. - #[instrument(skip(self, content), fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, content), fields(room_id = ?self.room().room_id())))] pub async fn send(&self, mut content: AnyMessageLikeEventContent) -> Result { // If this is a room event we're sending in a threaded timeline, we add the // thread relation ourselves. @@ -395,7 +395,7 @@ impl Timeline { /// * `content` - The content of the reply. /// /// * `in_reply_to` - The ID of the event to reply to. - #[instrument(skip(self, content))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, content)))] pub async fn send_reply( &self, content: RoomMessageEventContentWithoutRelation, @@ -466,7 +466,7 @@ impl Timeline { /// /// Only supports events for which [`EventTimelineItem::is_editable()`] /// returns `true`. - #[instrument(skip(self, new_content))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, new_content)))] pub async fn edit( &self, item_id: &TimelineEventItemId, @@ -582,7 +582,7 @@ impl Timeline { /// the attachment like a thumbnail, its size, duration etc. /// /// [`Media::get_media_content()`]: matrix_sdk::Media::get_media_content - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn send_attachment( &self, source: impl Into, @@ -609,7 +609,7 @@ impl Timeline { /// /// [`Media::get_media_content()`]: matrix_sdk::Media::get_media_content #[cfg(feature = "unstable-msc4274")] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn send_gallery(&self, gallery: GalleryConfig) -> SendGallery<'_> { SendGallery::new(self, gallery) } @@ -659,7 +659,7 @@ impl Timeline { /// Returns an error if the identifier doesn't match any event with a remote /// echo in the timeline, or if the event is removed from the timeline /// before all requests are handled. - #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = ?self.room().room_id())))] pub async fn fetch_details_for_event(&self, event_id: &EventId) -> Result<(), Error> { self.controller.fetch_in_reply_to_details(event_id).await } @@ -671,7 +671,7 @@ impl Timeline { /// /// If fetching the members fails, any affected timeline items will have /// the `sender_profile` set to [`TimelineDetails::Error`]. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn fetch_members(&self) { self.controller.set_sender_profiles_pending().await; match self.room().sync_members().await { @@ -689,7 +689,7 @@ impl Timeline { /// Contrary to [`Room::load_user_receipt()`] that only keeps track of read /// receipts received from the homeserver, this keeps also track of implicit /// read receipts in this timeline, i.e. when a room member sends an event. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn latest_user_read_receipt( &self, user_id: &UserId, @@ -704,7 +704,7 @@ impl Timeline { /// the position of the read receipt in the timeline even if the event it /// applies to is not visible in the timeline, unless the event is unknown /// by this timeline. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn latest_user_read_receipt_timeline_event_id( &self, user_id: &UserId, @@ -730,7 +730,7 @@ impl Timeline { /// focus mode and `hide_threaded_events` flag. /// /// Returns a boolean indicating if it sent the receipt or not. - #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = ?self.room().room_id())))] pub async fn send_single_receipt( &self, receipt_type: ReceiptType, @@ -764,7 +764,7 @@ impl Timeline { /// requests. /// /// This also unsets the unread marker of the room if necessary. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn send_multiple_receipts(&self, mut receipts: Receipts) -> Result<()> { if let Some(fully_read) = &receipts.fully_read && !self @@ -832,7 +832,7 @@ impl Timeline { /// # Returns /// /// A boolean indicating if the receipt was sent or not. - #[instrument(skip(self), fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = ?self.room().room_id())))] pub async fn mark_as_read(&self, receipt_type: ReceiptType) -> Result { if let Some(event_id) = self.controller.latest_event_id().await { self.send_single_receipt(receipt_type, event_id).await diff --git a/crates/matrix-sdk-ui/src/timeline/pagination.rs b/crates/matrix-sdk-ui/src/timeline/pagination.rs index 3fbbb15a88f..f36014a3720 100644 --- a/crates/matrix-sdk-ui/src/timeline/pagination.rs +++ b/crates/matrix-sdk-ui/src/timeline/pagination.rs @@ -29,7 +29,7 @@ impl super::Timeline { /// Add more events to the start of the timeline. /// /// Returns whether we hit the start of the timeline. - #[instrument(skip_all, fields(room_id = ?self.room().room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?self.room().room_id())))] pub async fn paginate_backwards(&self, mut num_events: u16) -> Result { match self.controller.focus() { TimelineFocusKind::Live { .. } => { diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index d64fd0a68ea..05c86a2420d 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -91,6 +91,15 @@ experimental-search = ["matrix-sdk-search"] experimental-element-recent-emojis = ["matrix-sdk-base/experimental-element-recent-emojis"] +# tracing #[instrument]'ation +instrument = [ + "tracing/attributes", + "matrix-sdk-base/instrument", + "matrix-sdk-common/instrument", + "matrix-sdk-indexeddb?/instrument", + "matrix-sdk-sqlite?/instrument", +] + [dependencies] anyhow = { workspace = true, optional = true } anymap2 = { version = "0.13.0", default-features = false } @@ -148,7 +157,7 @@ thiserror.workspace = true tokio-stream = { workspace = true, features = ["sync"] } tokio-util = "0.7.17" tower = { version = "0.5.2", features = ["util"], optional = true } -tracing = { workspace = true, features = ["attributes"] } +tracing = { workspace = true } uniffi = { workspace = true, optional = true } url = { workspace = true, features = ["serde"] } urlencoding = "2.1.3" diff --git a/crates/matrix-sdk/src/authentication/matrix/login_builder.rs b/crates/matrix-sdk/src/authentication/matrix/login_builder.rs index a5a8c062501..c5f08ec5f9d 100644 --- a/crates/matrix-sdk/src/authentication/matrix/login_builder.rs +++ b/crates/matrix-sdk/src/authentication/matrix/login_builder.rs @@ -24,7 +24,7 @@ use ruma::{ assign, serde::JsonObject, }; -use tracing::{info, instrument}; +use tracing::info; use super::MatrixAuth; #[cfg(feature = "sso-login")] @@ -165,12 +165,12 @@ impl LoginBuilder { /// # Panics /// /// Panics if a session was already restored or logged in. - #[instrument( + #[cfg_attr(feature = "instrument", tracing::instrument( target = "matrix_sdk::client", name = "login", skip_all, fields(method = self.login_method.tracing_desc()), - )] + ))] pub async fn send(self) -> Result { let client = &self.auth.client; let homeserver = client.homeserver(); @@ -307,7 +307,15 @@ where /// # Panics /// /// Panics if a session was already restored or logged in. - #[instrument(target = "matrix_sdk::client", name = "login", skip_all, fields(method = "sso"))] + #[cfg_attr( + feature = "instrument", + instrument( + target = "matrix_sdk::client", + name = "login", + skip_all, + fields(method = "sso") + ) + )] pub async fn send(self) -> Result { use std::io::Error as IoError; diff --git a/crates/matrix-sdk/src/authentication/matrix/mod.rs b/crates/matrix-sdk/src/authentication/matrix/mod.rs index 686fd748ffb..1c9729691db 100644 --- a/crates/matrix-sdk/src/authentication/matrix/mod.rs +++ b/crates/matrix-sdk/src/authentication/matrix/mod.rs @@ -37,7 +37,7 @@ use ruma::{ }; use serde::{Deserialize, Serialize}; use thiserror::Error; -use tracing::{debug, error, info, instrument}; +use tracing::{debug, error, info}; use crate::{ Client, Error, RefreshTokenError, Result, @@ -600,7 +600,7 @@ impl MatrixAuth { /// client.matrix_auth().register(request).await; /// # }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn register(&self, request: register::v3::Request) -> Result { let homeserver = self.client.homeserver(); info!("Registering to {homeserver}"); @@ -718,7 +718,7 @@ impl MatrixAuth { /// /// [`login`]: #method.login /// [`LoginBuilder::send()`]: crate::authentication::matrix::LoginBuilder::send - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn restore_session( &self, session: MatrixSession, diff --git a/crates/matrix-sdk/src/authentication/oauth/auth_code_builder.rs b/crates/matrix-sdk/src/authentication/oauth/auth_code_builder.rs index 27dd28a0ce6..b576402efce 100644 --- a/crates/matrix-sdk/src/authentication/oauth/auth_code_builder.rs +++ b/crates/matrix-sdk/src/authentication/oauth/auth_code_builder.rs @@ -20,7 +20,7 @@ use oauth2::{ use ruma::{ OwnedDeviceId, UserId, api::client::discovery::get_authorization_server_metadata::v1::Prompt, }; -use tracing::{info, instrument}; +use tracing::info; use url::Url; use super::{ClientRegistrationData, OAuth, OAuthError}; @@ -114,7 +114,10 @@ impl OAuthAuthCodeUrlBuilder { /// /// Returns an error if the client registration was not restored, or if a /// request fails. - #[instrument(target = "matrix_sdk::client", skip_all)] + #[cfg_attr( + feature = "instrument", + tracing::instrument(target = "matrix_sdk::client", skip_all) + )] pub async fn build(self) -> Result { let Self { oauth, registration_data, scopes, device_id, redirect_uri, prompt, login_hint } = self; diff --git a/crates/matrix-sdk/src/authentication/oauth/mod.rs b/crates/matrix-sdk/src/authentication/oauth/mod.rs index 0bfe8d00765..f53f6cc4083 100644 --- a/crates/matrix-sdk/src/authentication/oauth/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/mod.rs @@ -194,7 +194,7 @@ use ruma::{ use serde::{Deserialize, Serialize}; use sha2::Digest as _; use tokio::sync::Mutex; -use tracing::{debug, error, instrument, trace, warn}; +use tracing::{debug, error, trace, warn}; use url::Url; mod auth_code_builder; @@ -1159,7 +1159,7 @@ impl OAuth { /// will wait for the result of the first call. /// /// [`ClientBuilder::handle_refresh_tokens()`]: crate::ClientBuilder::handle_refresh_tokens() - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn refresh_access_token(&self) -> Result<(), RefreshTokenError> { macro_rules! fail { ($lock:expr, $err:expr) => { diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel/msc_4108.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel/msc_4108.rs index 192b03262dd..2f3db710229 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel/msc_4108.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/rendezvous_channel/msc_4108.rs @@ -23,7 +23,7 @@ use ruma::api::{ EndpointError, error::{FromHttpResponseError, HeaderDeserializationError, IntoHttpError}, }; -use tracing::{debug, instrument, trace}; +use tracing::{debug, trace}; use url::Url; use crate::{HttpError, RumaApiError, http_client::HttpClient}; @@ -170,7 +170,7 @@ impl Channel { /// device. /// /// The message must be of the `text/plain` content type. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn send(&mut self, message: Vec) -> Result<(), HttpError> { let etag = self.etag.clone(); @@ -237,7 +237,7 @@ impl Channel { } } - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] async fn receive_message_impl( client: &reqwest::Client, etag: Option, diff --git a/crates/matrix-sdk/src/authentication/oauth/qrcode/secure_channel/mod.rs b/crates/matrix-sdk/src/authentication/oauth/qrcode/secure_channel/mod.rs index 29c0fa025f7..b49f051c336 100644 --- a/crates/matrix-sdk/src/authentication/oauth/qrcode/secure_channel/mod.rs +++ b/crates/matrix-sdk/src/authentication/oauth/qrcode/secure_channel/mod.rs @@ -17,7 +17,7 @@ use matrix_sdk_base::crypto::types::qr_login::{ Msc4108IntentData, QrCodeData, QrCodeIntent, QrCodeIntentData, }; use serde::{Serialize, de::DeserializeOwned}; -use tracing::{instrument, trace}; +use tracing::trace; use url::Url; use vodozemac::ecies::{ CheckCode, Ecies, EstablishedEcies, InboundCreationResult, OutboundCreationResult, @@ -92,7 +92,7 @@ impl SecureChannel { &self.qr_code_data } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub(super) async fn connect(mut self) -> Result { trace!("Trying to connect the secure channel."); @@ -155,7 +155,7 @@ pub(super) struct EstablishedSecureChannel { impl EstablishedSecureChannel { /// Establish a secure channel from a scanned QR code. - #[instrument(skip(client))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(client)))] pub(super) async fn from_qr_code( client: reqwest::Client, qr_code_data: &QrCodeData, diff --git a/crates/matrix-sdk/src/client/builder/mod.rs b/crates/matrix-sdk/src/client/builder/mod.rs index 2c51ffe0eed..8fd527905c2 100644 --- a/crates/matrix-sdk/src/client/builder/mod.rs +++ b/crates/matrix-sdk/src/client/builder/mod.rs @@ -42,7 +42,7 @@ use thiserror::Error; #[cfg(feature = "experimental-search")] use tokio::sync::Mutex; use tokio::sync::OnceCell; -use tracing::{Span, debug, field::debug, instrument}; +use tracing::{Span, debug, field::debug}; use super::{Client, ClientInner}; #[cfg(feature = "e2e-encryption")] @@ -540,7 +540,10 @@ impl ClientBuilder { /// server discovery request is made which can fail; if you didn't set /// [`server_versions(false)`][Self::server_versions], that amounts to /// another request that can fail - #[instrument(skip_all, target = "matrix_sdk::client", fields(homeserver))] + #[cfg_attr( + feature = "instrument", + instrument(skip_all, target = "matrix_sdk::client", fields(homeserver)) + )] pub async fn build(self) -> Result { debug!("Starting to build the Client"); diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index e9610727716..f16e6d014cb 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -1388,7 +1388,7 @@ impl Client { /// # Panics /// /// Panics if a session was already restored or logged in. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn restore_session(&self, session: impl Into) -> Result<()> { self.restore_session_with(session, RoomLoadSettings::default()).await } @@ -1403,7 +1403,7 @@ impl Client { /// # Panics /// /// Panics if a session was already restored or logged in. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn restore_session_with( &self, session: impl Into, @@ -1506,7 +1506,7 @@ impl Client { /// /// let response = client.sync_once(sync_settings).await.unwrap(); /// # }; - #[instrument(skip(self, definition))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, definition)))] pub async fn get_or_upload_filter( &self, filter_name: &str, @@ -1616,7 +1616,7 @@ impl Client { /// # Arguments /// /// * `room_id` - The `RoomId` of the room to be joined. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn join_room_by_id(&self, room_id: &RoomId) -> Result { // See who invited us to this room, if anyone. Note we have to do this before // making the `/join` request, otherwise we could race against the sync. @@ -2655,7 +2655,7 @@ impl Client { /// [`get_or_upload_filter()`]: #method.get_or_upload_filter /// [long polling]: #long-polling /// [filtered]: #filtering-events - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn sync_once( &self, sync_settings: crate::config::SyncSettings, @@ -2823,7 +2823,7 @@ impl Client { /// .await; /// }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn sync_with_callback( &self, sync_settings: crate::config::SyncSettings, @@ -2903,7 +2903,7 @@ impl Client { /// .await; /// }; /// ``` - #[instrument(skip(self, callback))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, callback)))] pub async fn sync_with_result_callback( &self, sync_settings: crate::config::SyncSettings, @@ -2968,7 +2968,7 @@ impl Client { /// # anyhow::Ok(()) }; /// ``` #[allow(unknown_lints, clippy::let_with_type_underscore)] // triggered by instrument macro - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn sync_stream( &self, mut sync_settings: crate::config::SyncSettings, diff --git a/crates/matrix-sdk/src/client/thread_subscriptions.rs b/crates/matrix-sdk/src/client/thread_subscriptions.rs index 27d8f8719db..52173c6424e 100644 --- a/crates/matrix-sdk/src/client/thread_subscriptions.rs +++ b/crates/matrix-sdk/src/client/thread_subscriptions.rs @@ -36,7 +36,7 @@ use tokio::sync::{ Mutex, OwnedMutexGuard, mpsc::{Receiver, Sender, channel}, }; -use tracing::{debug, instrument, trace, warn}; +use tracing::{debug, trace, warn}; use crate::{Client, Result, client::WeakClient}; @@ -82,7 +82,7 @@ impl GuardedStoreAccess { /// Saves the tokens in the database. /// /// Returns whether the list of tokens is empty or not. - #[instrument(skip_all, fields(num_tokens = tokens.len()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(num_tokens = tokens.len())))] async fn save_catchup_tokens( &self, tokens: Vec, @@ -187,7 +187,7 @@ impl ThreadSubscriptionCatchup { /// Store the new subscriptions changes, received via the sync response or /// from the msc4308 companion endpoint. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn sync_subscriptions( &self, subscribed: BTreeMap>, @@ -266,7 +266,7 @@ impl ThreadSubscriptionCatchup { /// relevant information. /// /// [MSC4308]: https://github.com/matrix-org/matrix-spec-proposals/pull/4308 - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn thread_subscriptions_catchup_task(this: Arc, mut ping_receiver: Receiver<()>) { loop { // Load the current catchup token. diff --git a/crates/matrix-sdk/src/encryption/backups/mod.rs b/crates/matrix-sdk/src/encryption/backups/mod.rs index f598e51b6b6..4f9081a40d1 100644 --- a/crates/matrix-sdk/src/encryption/backups/mod.rs +++ b/crates/matrix-sdk/src/encryption/backups/mod.rs @@ -52,7 +52,7 @@ use ruma::{ serde::Raw, }; use tokio_stream::wrappers::{BroadcastStream, errors::BroadcastStreamRecvError}; -use tracing::{Span, error, info, instrument, trace, warn}; +use tracing::{Span, error, info, trace, warn}; pub mod futures; pub(crate) mod types; @@ -209,7 +209,7 @@ impl Backups { /// assert_eq!(backups.state(), BackupState::Unknown); /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all, fields(version))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(version)))] pub async fn disable(&self) -> Result<(), Error> { let _guard = self.client.locks().backup_modify_lock.lock().await; @@ -683,7 +683,7 @@ impl Backups { ret } - #[instrument(skip(self, olm_machine, request))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, olm_machine, request)))] async fn send_backup_request( &self, olm_machine: &OlmMachine, @@ -801,7 +801,7 @@ impl Backups { /// /// Returns true if backups were just enabled or were already enabled, /// otherwise false. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn maybe_enable_backups( &self, maybe_recovery_key: &str, @@ -992,7 +992,7 @@ impl Backups { /// Listen for `m.secret.send` to-device messages and check the secret inbox /// if we do receive one. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn secret_send_event_handler(_: ToDeviceSecretSendEvent, client: Client) { let olm_machine = client.olm_machine().await; diff --git a/crates/matrix-sdk/src/encryption/mod.rs b/crates/matrix-sdk/src/encryption/mod.rs index 0f7ee1b3ac1..619ef99dbdc 100644 --- a/crates/matrix-sdk/src/encryption/mod.rs +++ b/crates/matrix-sdk/src/encryption/mod.rs @@ -85,7 +85,7 @@ use serde::{Deserialize, de::Error as _}; use tasks::BundleReceiverTask; use tokio::sync::{Mutex, RwLockReadGuard}; use tokio_stream::wrappers::errors::BroadcastStreamRecvError; -use tracing::{debug, error, instrument, warn}; +use tracing::{debug, error, warn}; use url::Url; use vodozemac::Curve25519PublicKey; @@ -535,7 +535,7 @@ impl Client { /// # Panics /// /// Panics if no key query needs to be done. - #[instrument(skip(self, device_keys))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, device_keys)))] pub(crate) async fn keys_query( &self, request_id: &TransactionId, @@ -669,7 +669,7 @@ impl Client { /// /// Panics if the client isn't logged in, or if no encryption keys need to /// be uploaded. - #[instrument(skip(self, request))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, request)))] pub(crate) async fn keys_upload( &self, request_id: &TransactionId, @@ -826,7 +826,7 @@ impl Client { Ok(()) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn send_outgoing_requests(&self) -> Result<()> { const MAX_CONCURRENT_REQUESTS: usize = 20; diff --git a/crates/matrix-sdk/src/encryption/recovery/mod.rs b/crates/matrix-sdk/src/encryption/recovery/mod.rs index 370ef35f150..80c413971b6 100644 --- a/crates/matrix-sdk/src/encryption/recovery/mod.rs +++ b/crates/matrix-sdk/src/encryption/recovery/mod.rs @@ -231,7 +231,7 @@ impl Recovery { /// /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn enable(&self) -> Enable<'_> { Enable::new(self) } @@ -257,7 +257,7 @@ impl Recovery { /// /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn enable_backup(&self) -> Result<()> { if !self.client.encryption().backups().fetch_exists_on_server().await? { self.mark_backup_as_enabled().await?; @@ -298,7 +298,7 @@ impl Recovery { /// /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn disable(&self) -> Result<()> { self.client.encryption().backups().disable().await?; @@ -353,7 +353,7 @@ impl Recovery { /// recovery.reset_key().with_passphrase("my passphrase").await; /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn reset_key(&self) -> Reset<'_> { // TODO: Should this only be possible if we're in the RecoveryState::Enabled // state? Otherwise we'll create a new secret store but won't be able to @@ -380,7 +380,7 @@ impl Recovery { /// .await?; /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn recover_and_reset<'a>(&'a self, old_key: &'a str) -> RecoverAndReset<'a> { RecoverAndReset::new(self, old_key) } @@ -483,7 +483,7 @@ impl Recovery { /// assert_eq!(recovery.state(), RecoveryState::Enabled); /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn recover(&self, recovery_key: &str) -> Result<()> { let store = self.client.encryption().secret_storage().open_secret_store(recovery_key).await?; @@ -695,12 +695,12 @@ impl Recovery { } } - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] async fn secret_send_event_handler(_: ToDeviceSecretSendEvent, client: Client) { client.encryption().recovery().update_recovery_state_no_fail().await; } - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] async fn default_key_event_handler(_: SecretStorageDefaultKeyEvent, client: Client) { client.encryption().recovery().update_recovery_state_no_fail().await; } @@ -745,7 +745,7 @@ impl Recovery { } } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn update_state_after_keys_query(&self, response: &get_keys::v3::Response) { if let Some(user_id) = self.client.user_id() && response.master_keys.contains_key(user_id) diff --git a/crates/matrix-sdk/src/encryption/secret_storage/secret_store.rs b/crates/matrix-sdk/src/encryption/secret_storage/secret_store.rs index 0f0d5d7cea8..60f22a53879 100644 --- a/crates/matrix-sdk/src/encryption/secret_storage/secret_store.rs +++ b/crates/matrix-sdk/src/encryption/secret_storage/secret_store.rs @@ -26,7 +26,7 @@ use serde_json::value::to_raw_value; use tracing::{ Span, error, field::{debug, display}, - info, instrument, warn, + info, warn, }; use zeroize::Zeroize; @@ -399,7 +399,10 @@ impl SecretStore { /// ``` /// /// [`Device`]: crate::encryption::identities::Device - #[instrument(fields(user_id, device_id, cross_signing_status))] + #[cfg_attr( + feature = "instrument", + instrument(fields(user_id, device_id, cross_signing_status)) + )] pub async fn import_secrets(&self) -> Result<()> { let olm_machine = self.client.olm_machine().await; let olm_machine = olm_machine.as_ref().ok_or(crate::Error::NoOlmMachine)?; diff --git a/crates/matrix-sdk/src/encryption/tasks.rs b/crates/matrix-sdk/src/encryption/tasks.rs index 2eb774c632c..c675f0ebe30 100644 --- a/crates/matrix-sdk/src/encryption/tasks.rs +++ b/crates/matrix-sdk/src/encryption/tasks.rs @@ -28,7 +28,7 @@ use ruma::events::room::encrypted::{EncryptedEventScheme, OriginalSyncRoomEncryp use ruma::serde::JsonCastable; use ruma::{OwnedEventId, OwnedRoomId, serde::Raw}; use tokio::sync::{Mutex, mpsc}; -use tracing::{debug, info, instrument, trace, warn}; +use tracing::{debug, info, trace, warn}; use crate::{ Client, Room, @@ -568,7 +568,7 @@ impl BundleReceiverTask { /// other hand, it is **not** possible for a race to mean that we end up /// processing the bundle zero times: we can be sure that at least one /// thread will process it. - #[instrument(skip(room), fields(room_id = %room.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(room), fields(room_id = %room.room_id())))] async fn handle_bundle(room: &Room, bundle_info: &RoomKeyBundleInfo) { if shared_room_history::should_accept_key_bundle(room, bundle_info).await { info!(room_id = %room.room_id(), "Accepting a late key bundle."); diff --git a/crates/matrix-sdk/src/event_cache/caches/pagination.rs b/crates/matrix-sdk/src/event_cache/caches/pagination.rs index 18fe74604c4..27563d2976c 100644 --- a/crates/matrix-sdk/src/event_cache/caches/pagination.rs +++ b/crates/matrix-sdk/src/event_cache/caches/pagination.rs @@ -26,7 +26,7 @@ use matrix_sdk_base::{ SendOutsideWasm, SyncOutsideWasm, event_cache::Event, executor::AbortOnDrop, timeout::timeout, }; use matrix_sdk_common::executor::spawn; -use tracing::{debug, instrument, trace, warn}; +use tracing::{debug, trace, warn}; use super::super::Result; @@ -57,7 +57,7 @@ where /// - either we've reached the start of the timeline, /// - or we've obtained enough events to fulfill the requested number of /// events. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn run_backwards_until( &self, num_requested_events: u16, @@ -89,7 +89,7 @@ where /// /// This automatically takes care of waiting for a pagination token from /// sync, if we haven't done that before. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub async fn run_backwards_once(&self, batch_size: u16) -> Result { loop { if let Some(outcome) = self.run_backwards_impl(batch_size).await? { diff --git a/crates/matrix-sdk/src/event_cache/mod.rs b/crates/matrix-sdk/src/event_cache/mod.rs index 37d456c119a..ad2ccbde2c1 100644 --- a/crates/matrix-sdk/src/event_cache/mod.rs +++ b/crates/matrix-sdk/src/event_cache/mod.rs @@ -48,7 +48,7 @@ use tokio::sync::{ broadcast::{Receiver, Sender, channel}, mpsc, }; -use tracing::{error, instrument, trace}; +use tracing::{error, trace}; use crate::{ Client, @@ -603,7 +603,7 @@ impl EventCacheInner { } /// Handles a single set of room updates at once. - #[instrument(skip(self, updates))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, updates)))] async fn handle_room_updates(&self, updates: RoomUpdates) -> Result<()> { // First, take the lock that indicates we're processing updates, to avoid // handling multiple updates concurrently. diff --git a/crates/matrix-sdk/src/event_handler/mod.rs b/crates/matrix-sdk/src/event_handler/mod.rs index 946066d261d..cfabc4091bc 100644 --- a/crates/matrix-sdk/src/event_handler/mod.rs +++ b/crates/matrix-sdk/src/event_handler/mod.rs @@ -62,7 +62,7 @@ use pin_project_lite::pin_project; use ruma::{OwnedRoomId, events::BooleanType, push::Action, serde::Raw}; use serde::{Deserialize, de::DeserializeOwned}; use serde_json::value::RawValue as RawJsonValue; -use tracing::{debug, error, field::debug, instrument, warn}; +use tracing::{debug, error, field::debug, warn}; use self::maps::EventHandlerMaps; use crate::{Client, Room}; @@ -497,7 +497,7 @@ impl Client { Ok(()) } - #[instrument(skip_all, fields(?event_kind, ?event_type, room_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?event_kind, ?event_type, room_id)))] async fn call_event_handlers( &self, room: Option<&Room>, diff --git a/crates/matrix-sdk/src/room/calls.rs b/crates/matrix-sdk/src/room/calls.rs index 083f618abee..01fa81a1f93 100644 --- a/crates/matrix-sdk/src/room/calls.rs +++ b/crates/matrix-sdk/src/room/calls.rs @@ -23,7 +23,6 @@ use ruma::{ }; use thiserror::Error; use tokio::sync::broadcast; -use tracing::instrument; use crate::{Room, event_handler::EventHandlerDropGuard, room::EventSource}; @@ -52,7 +51,7 @@ impl Room { /// /// The event can then be sent with [`Room::send`] or a /// [`crate::send_queue::RoomSendQueue`]. - #[instrument(skip(self), fields(room = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room = %self.room_id())))] pub async fn make_decline_call_event( &self, notification_event_id: &EventId, diff --git a/crates/matrix-sdk/src/room/edit.rs b/crates/matrix-sdk/src/room/edit.rs index 246590e826f..f59a79b780b 100644 --- a/crates/matrix-sdk/src/room/edit.rs +++ b/crates/matrix-sdk/src/room/edit.rs @@ -30,7 +30,6 @@ use ruma::{ }, }; use thiserror::Error; -use tracing::instrument; use super::EventSource; use crate::Room; @@ -115,7 +114,7 @@ impl Room { /// /// The event can then be sent with [`Room::send`] or a /// [`crate::send_queue::RoomSendQueue`]. - #[instrument(skip(self, new_content), fields(room = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, new_content), fields(room = %self.room_id())))] pub async fn make_edit_event( &self, event_id: &EventId, diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index d4389effc4a..8ff26a00b7b 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -157,7 +157,7 @@ use ruma::{ use serde::de::DeserializeOwned; use thiserror::Error; use tokio::{join, sync::broadcast}; -use tracing::{debug, error, info, instrument, trace, warn}; +use tracing::{debug, error, info, trace, warn}; use self::futures::{SendAttachment, SendMessageLikeEvent, SendRawMessageLikeEvent}; pub use self::{ @@ -263,7 +263,7 @@ impl PushContext { /// Compute the push rules for a given event, with extra logging to help /// debugging. #[doc(hidden)] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn traced_for_event(&self, event: &Raw) -> Vec { let rules = self .push_rules @@ -407,7 +407,7 @@ impl Room { /// /// Only invited and joined rooms can be left. #[doc(alias = "reject_invitation")] - #[instrument(skip_all, fields(room_id = ?self.inner.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?self.inner.room_id())))] async fn leave_impl(&self) -> (Result<()>, &Room) { let state = self.state(); if state == RoomState::Left { @@ -611,7 +611,7 @@ impl Room { /// assert!(room.messages(options).await.is_ok()); /// # }; /// ``` - #[instrument(skip_all, fields(room_id = ?self.inner.room_id(), ?options))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = ?self.inner.room_id(), ?options)))] pub async fn messages(&self, options: MessagesOptions) -> Result { let room_id = self.inner.room_id(); let request = options.into_request(room_id); @@ -1969,7 +1969,7 @@ impl Room { /// * `user_id` - The user to ban with `UserId`. /// /// * `reason` - The reason for banning this user. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn ban_user(&self, user_id: &UserId, reason: Option<&str>) -> Result<()> { let request = assign!( ban_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), @@ -1986,7 +1986,7 @@ impl Room { /// * `user_id` - The user to unban with `UserId`. /// /// * `reason` - The reason for unbanning this user. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn unban_user(&self, user_id: &UserId, reason: Option<&str>) -> Result<()> { let request = assign!( unban_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), @@ -2004,7 +2004,7 @@ impl Room { /// room. /// /// * `reason` - Optional reason why the room member is being kicked out. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn kick_user(&self, user_id: &UserId, reason: Option<&str>) -> Result<()> { let request = assign!( kick_user::v3::Request::new(self.room_id().to_owned(), user_id.to_owned()), @@ -2019,7 +2019,7 @@ impl Room { /// # Arguments /// /// * `user_id` - The `UserId` of the user to invite to the room. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn invite_user_by_id(&self, user_id: &UserId) -> Result<()> { #[cfg(feature = "e2e-encryption")] if self.client.inner.enable_share_history_on_invite { @@ -2043,7 +2043,7 @@ impl Room { /// # Arguments /// /// * `invite_id` - A third party id of a user to invite to the room. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn invite_user_by_3pid(&self, invite_id: Invite3pid) -> Result<()> { let recipient = InvitationRecipient::ThirdPartyId(invite_id); let request = invite_user::v3::Request::new(self.room_id().to_owned(), recipient); @@ -2121,7 +2121,7 @@ impl Room { Ok(()) } - #[instrument(name = "typing_notice", skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(name = "typing_notice", skip(self)))] async fn send_typing_notice(&self, typing: bool) -> Result<()> { let typing = if typing { self.client @@ -2163,7 +2163,7 @@ impl Room { /// [`ReceiptType::FullyRead`][create_receipt::v3::ReceiptType::FullyRead]. /// /// * `event_id` - The `EventId` of the event to set the receipt on. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn send_single_receipt( &self, receipt_type: create_receipt::v3::ReceiptType, @@ -2209,7 +2209,7 @@ impl Room { /// * `receipts` - The `Receipts` to send. /// /// If `receipts` is empty, this is a no-op. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn send_multiple_receipts(&self, receipts: Receipts) -> Result<()> { if receipts.is_empty() { return Ok(()); @@ -2342,7 +2342,7 @@ impl Room { /// } /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn enable_encryption(&self) -> Result<()> { self.enable_encryption_inner(false).await } @@ -2379,7 +2379,7 @@ impl Room { /// } /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] #[cfg(feature = "experimental-encrypted-state-events")] pub async fn enable_encryption_with_state_event_encryption(&self) -> Result<()> { self.enable_encryption_inner(true).await @@ -2394,7 +2394,7 @@ impl Room { // TODO: expose this publicly so people can pre-share a group session if // e.g. a user starts to type a message for a room. #[cfg(feature = "e2e-encryption")] - #[instrument(skip_all, fields(room_id = ?self.room_id()))] + #[cfg_attr(feature = "instrument", skip_all, fields(room_id = ?self.room_id()))] async fn preshare_room_key(&self) -> Result<()> { self.ensure_room_joined()?; @@ -2438,7 +2438,7 @@ impl Room { /// /// Panics if the client isn't logged in. #[cfg(feature = "e2e-encryption")] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn share_room_key(&self) -> Result<()> { self.ensure_room_joined()?; @@ -2460,7 +2460,7 @@ impl Room { /// Warning: This waits until a sync happens and does not return if no sync /// is happening. It can also return early when the room is not a joined /// room anymore. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn sync_up(&self) { while !self.is_synced() && self.state() == RoomState::Joined { let wait_for_beat = self.client.inner.sync_beat.listen(); @@ -2619,7 +2619,7 @@ impl Room { /// } /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all, fields(event_type, room_id = ?self.room_id(), transaction_id, is_room_encrypted, event_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(event_type, room_id = ?self.room_id(), transaction_id, is_room_encrypted, event_id)))] pub fn send_raw<'a>( &'a self, event_type: &'a str, @@ -2677,7 +2677,7 @@ impl Room { /// /// [`upload()`]: crate::Media::upload /// [`send()`]: Self::send - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn send_attachment<'a>( &'a self, filename: impl Into, @@ -2715,7 +2715,7 @@ impl Room { /// /// * `store_in_cache` - A boolean defining whether the uploaded media will /// be stored in the cache immediately after a successful upload. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(super) async fn prepare_and_send_attachment<'a>( &'a self, filename: String, @@ -3057,7 +3057,7 @@ impl Room { /// # anyhow::Ok(()) }; /// ``` #[cfg(not(feature = "experimental-encrypted-state-events"))] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn send_state_event( &self, content: impl StateEventContent, @@ -3116,7 +3116,7 @@ impl Room { /// /// [msc4362]: https://github.com/matrix-org/matrix-spec-proposals/blob/travis/msc/encrypted-state/proposals/4362-encrypted-state.md #[cfg(feature = "experimental-encrypted-state-events")] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn send_state_event<'a>( &'a self, content: impl StateEventContent, @@ -3279,7 +3279,7 @@ impl Room { /// # anyhow::Ok(()) }; /// ``` #[cfg(not(feature = "experimental-encrypted-state-events"))] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn send_state_event_raw( &self, event_type: &str, @@ -3340,7 +3340,7 @@ impl Room { /// /// [msc4362]: https://github.com/matrix-org/matrix-spec-proposals/pull/4362 #[cfg(feature = "experimental-encrypted-state-events")] - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub fn send_state_event_raw<'a>( &'a self, event_type: &'a str, @@ -3384,7 +3384,7 @@ impl Room { /// } /// # anyhow::Ok(()) }; /// ``` - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub async fn redact( &self, event_id: &EventId, @@ -3659,7 +3659,7 @@ impl Room { /// Retrieves a [`PushContext`] that can be used to compute the push actions /// for events, with a choice to include thread subscriptions or not, /// based on the extra `with_threads_subscriptions` parameter. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] pub(crate) async fn push_context_internal( &self, with_threads_subscriptions: bool, @@ -4319,7 +4319,7 @@ impl Room { /// - An `Ok` result if the subscription was successful, or if the server /// skipped an automatic subscription (as the user unsubscribed from the /// thread after the event causing the automatic subscription). - #[instrument(skip(self), fields(room_id = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = %self.room_id())))] pub async fn subscribe_thread( &self, thread_root: OwnedEventId, @@ -4406,7 +4406,7 @@ impl Room { /// - An `Ok` result if the unsubscription was successful, or the thread was /// already unsubscribed. /// - A 404 error if the event isn't known, or isn't a thread root. - #[instrument(skip(self), fields(room_id = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = %self.room_id())))] pub async fn unsubscribe_thread(&self, thread_root: OwnedEventId) -> Result<()> { self.client .send(unsubscribe_thread::unstable::Request::new( @@ -4449,7 +4449,7 @@ impl Room { /// event couldn't be found, or the event isn't a thread. /// - An error if the request fails for any other reason, such as a network /// error. - #[instrument(skip(self), fields(room_id = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = %self.room_id())))] pub async fn fetch_thread_subscription( &self, thread_root: OwnedEventId, diff --git a/crates/matrix-sdk/src/room/reply.rs b/crates/matrix-sdk/src/room/reply.rs index ab340d02c95..344eab6f748 100644 --- a/crates/matrix-sdk/src/room/reply.rs +++ b/crates/matrix-sdk/src/room/reply.rs @@ -29,7 +29,6 @@ use ruma::{ }, }; use thiserror::Error; -use tracing::instrument; use super::{EventSource, Room}; @@ -89,7 +88,7 @@ impl Room { /// * `content` - The content to reply with /// * `event_id` - ID of the event to reply to /// * `enforce_thread` - Whether to enforce a thread relation - #[instrument(skip(self, content), fields(room = %self.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, content), fields(room = %self.room_id())))] pub async fn make_reply_event( &self, content: RoomMessageEventContentWithoutRelation, diff --git a/crates/matrix-sdk/src/room/shared_room_history.rs b/crates/matrix-sdk/src/room/shared_room_history.rs index 81b012fc8fb..b60c97c219c 100644 --- a/crates/matrix-sdk/src/room/shared_room_history.rs +++ b/crates/matrix-sdk/src/room/shared_room_history.rs @@ -27,7 +27,7 @@ use ruma::{ api::error::ErrorKind, events::room::{MediaSource, history_visibility::HistoryVisibility}, }; -use tracing::{debug, info, instrument, warn}; +use tracing::{debug, info, warn}; use crate::{Error, Result, Room}; @@ -35,7 +35,7 @@ use crate::{Error, Result, Room}; /// as per [MSC4268]. /// /// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268 -#[instrument(skip(room), fields(room_id = ?room.room_id()))] +#[cfg_attr(feature = "instrument", tracing::instrument(skip(room), fields(room_id = ?room.room_id())))] pub(super) async fn share_room_history(room: &Room, user_id: OwnedUserId) -> Result<()> { let client = &room.client; @@ -213,7 +213,7 @@ pub(crate) fn should_process_room_pending_key_bundle_details( /// sent the room key bundle. /// /// [MSC4268]: https://github.com/matrix-org/matrix-spec-proposals/pull/4268 -#[instrument(skip(room), fields(room_id = ?room.room_id(), bundle_sender))] +#[cfg_attr(feature = "instrument", tracing::instrument(skip(room), fields(room_id = ?room.room_id(), bundle_sender)))] pub(crate) async fn maybe_accept_key_bundle(room: &Room, inviter: &UserId) -> Result<()> { // TODO: retry this if it gets interrupted or it fails. // TODO: do this in the background. diff --git a/crates/matrix-sdk/src/room_preview.rs b/crates/matrix-sdk/src/room_preview.rs index 5554f780b5a..13a886f8ff7 100644 --- a/crates/matrix-sdk/src/room_preview.rs +++ b/crates/matrix-sdk/src/room_preview.rs @@ -27,7 +27,7 @@ use ruma::{ room::{JoinRuleSummary, RoomType}, }; use tokio::try_join; -use tracing::{instrument, warn}; +use tracing::warn; use crate::{Client, Error, Room, room_directory_search::RoomDirectorySearch}; @@ -132,7 +132,7 @@ impl RoomPreview { ) } - #[instrument(skip(client))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(client)))] pub(crate) async fn from_remote_room( client: &Client, room_id: OwnedRoomId, diff --git a/crates/matrix-sdk/src/send_queue/mod.rs b/crates/matrix-sdk/src/send_queue/mod.rs index 32217e447c8..fcb5c3bba28 100644 --- a/crates/matrix-sdk/src/send_queue/mod.rs +++ b/crates/matrix-sdk/src/send_queue/mod.rs @@ -173,7 +173,7 @@ use ruma::{ serde::Raw, }; use tokio::sync::{Mutex, Notify, OwnedMutexGuard, broadcast, oneshot}; -use tracing::{debug, error, info, instrument, trace, warn}; +use tracing::{debug, error, info, trace, warn}; use crate::{ Client, Media, Room, TransmissionProgress, @@ -654,7 +654,7 @@ impl RoomSendQueue { /// It only progresses forward: nothing can be cancelled at any point, which /// makes the implementation not overly complicated to follow. #[allow(clippy::too_many_arguments)] - #[instrument(skip_all, fields(room_id = %room.room_id()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(room_id = %room.room_id())))] async fn sending_task( room: WeakRoom, queue: QueueStorage, @@ -1935,7 +1935,7 @@ impl QueueStorage { } /// Reacts to the given local echo of an event. - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn react( &self, transaction_id: &TransactionId, @@ -2132,7 +2132,7 @@ impl QueueStorage { /// /// Returns true if the dependent request has been sent (or should not be /// retried later). - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn try_apply_single_dependent_request( &self, client: &Client, @@ -2368,7 +2368,7 @@ impl QueueStorage { Ok(true) } - #[instrument(skip(self))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self)))] async fn apply_dependent_requests( &self, new_updates: &mut Vec, @@ -2734,7 +2734,7 @@ impl SendHandle { /// /// Returns true if the sending could be aborted, false if not (i.e. the /// event had already been sent). - #[instrument(skip(self), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id)))] pub async fn abort(&self) -> Result { trace!("received an abort request"); @@ -2774,7 +2774,7 @@ impl SendHandle { /// /// Returns true if the event to be sent was replaced, false if not (i.e. /// the event had already been sent). - #[instrument(skip(self, new_content), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, new_content), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id)))] pub async fn edit_raw( &self, new_content: Raw, @@ -2898,7 +2898,7 @@ impl SendHandle { /// /// If returning `Ok(None)`; this means the reaction couldn't be sent /// because the event is already a remote one. - #[instrument(skip(self), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(room_id = %self.room.inner.room.room_id(), txn_id = %self.transaction_id)))] pub async fn react( &self, key: String, diff --git a/crates/matrix-sdk/src/send_queue/upload.rs b/crates/matrix-sdk/src/send_queue/upload.rs index e45bacc1e3c..7fbd9721cea 100644 --- a/crates/matrix-sdk/src/send_queue/upload.rs +++ b/crates/matrix-sdk/src/send_queue/upload.rs @@ -46,7 +46,7 @@ use ruma::{ }, }, }; -use tracing::{Span, debug, error, instrument, trace, warn}; +use tracing::{Span, debug, error, trace, warn}; use super::{QueueStorage, QueueThumbnailInfo, RoomSendQueue, RoomSendQueueError}; use crate::{ @@ -195,7 +195,7 @@ impl RoomSendQueue { /// and can be retrieved at any time, by calling /// [`Media::get_media_content()`] with the `MediaSource` that can be found /// in the local or remote echo, and using a `MediaFormat::File`. - #[instrument(skip_all, fields(event_txn))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(event_txn)))] pub async fn send_attachment( &self, filename: impl Into, @@ -301,7 +301,7 @@ impl RoomSendQueue { /// [`Media::get_media_content()`] with the `MediaSource` that can be found /// in the local or remote echo, and using a `MediaFormat::File`. #[cfg(feature = "unstable-msc4274")] - #[instrument(skip_all, fields(event_txn))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(event_txn)))] pub async fn send_gallery( &self, gallery: GalleryConfig, @@ -684,7 +684,7 @@ impl QueueStorage { /// uploaded. In this case, the media event has also been removed from /// the send queue. If it returns false, then the uploads already /// happened, and the event sending *may* have started. - #[instrument(skip(self, handles))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, handles)))] pub(super) async fn abort_upload( &self, event_txn: &TransactionId, @@ -803,7 +803,7 @@ impl QueueStorage { Ok(true) } - #[instrument(skip(self, caption, formatted_caption))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, caption, formatted_caption)))] pub(super) async fn edit_media_caption( &self, txn: &TransactionId, diff --git a/crates/matrix-sdk/src/sliding_sync/list/mod.rs b/crates/matrix-sdk/src/sliding_sync/list/mod.rs index f8eddcc3ede..785720c421e 100644 --- a/crates/matrix-sdk/src/sliding_sync/list/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/list/mod.rs @@ -13,7 +13,6 @@ use futures_core::Stream; use ruma::{api::client::sync::sync_events::v5 as http, assign, events::StateEventType}; use serde::{Deserialize, Serialize}; use tokio::sync::broadcast::Sender; -use tracing::{instrument, warn}; pub use self::builder::*; pub(super) use self::{frozen::FrozenSlidingSyncList, request_generator::*}; @@ -160,7 +159,7 @@ impl SlidingSyncList { /// - `maximum_number_of_rooms`: the `lists.$this_list.count` value, i.e. /// maximum number of available rooms in this list, as defined by the /// server. - #[instrument(skip(self), fields(name = self.name()))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(name = self.name())))] pub(super) fn update(&mut self, maximum_number_of_rooms: Option) -> Result { // Make sure to update the generator state first; ordering matters because // `update_room_list` observes the latest ranges in the response. @@ -284,7 +283,7 @@ impl SlidingSyncListInner { /// Build a [`http::request::List`] based on the current state of the /// request generator. - #[instrument(skip(self), fields(name = self.name))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip(self), fields(name = self.name)))] fn request(&self, ranges: Ranges) -> http::request::List { let ranges = ranges.into_iter().map(|r| ((*r.start()).into(), (*r.end()).into())).collect(); @@ -326,7 +325,7 @@ impl SlidingSyncListInner { /// Send a message over the internal channel if there is a receiver, i.e. if /// the sync loop is running. - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] fn internal_channel_send_if_possible(&self, message: SlidingSyncInternalMessage) { // If there is no receiver, the send will fail, but that's OK here. let _ = self.sliding_sync_internal_channel_sender.send(message); diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 5468bbded63..d0557e1754c 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -45,7 +45,7 @@ use tokio::{ select, sync::{Mutex as AsyncMutex, OwnedMutexGuard, RwLock as AsyncRwLock, broadcast::Sender}, }; -use tracing::{Instrument, Span, debug, error, info, instrument, trace, warn}; +use tracing::{Instrument, Span, debug, error, info, trace, warn}; pub use self::{builder::*, client::VersionBuilderError, error::*, list::*}; use self::{cache::restore_sliding_sync_state, client::SlidingSyncResponseProcessor}; @@ -257,7 +257,7 @@ impl SlidingSync { } /// Handle the HTTP response. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] async fn handle_response( &self, mut sliding_sync_response: http::Response, @@ -676,7 +676,7 @@ impl SlidingSync { /// /// Public for testing purposes only. #[doc(hidden)] - #[instrument(skip_all, fields(conn_id = self.inner.id, pos, timeout))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(conn_id = self.inner.id, pos, timeout)))] pub async fn sync_once(&self) -> Result { let (request, request_config, position_guard) = self.generate_sync_request().await?; @@ -698,7 +698,7 @@ impl SlidingSync { /// return `Err(…)`. An `Err` will _always_ lead to the `Stream` /// termination. #[allow(unknown_lints, clippy::let_with_type_underscore)] // triggered by instrument macro - #[instrument(name = "sync_stream", skip_all, fields(conn_id = self.inner.id, with_e2ee = self.is_e2ee_enabled()))] + #[cfg_attr(feature = "instrument", tracing::instrument(name = "sync_stream", skip_all, fields(conn_id = self.inner.id, with_e2ee = self.is_e2ee_enabled())))] pub fn sync(&self) -> impl Stream> + '_ { debug!("Starting sync stream"); @@ -844,14 +844,14 @@ fn subscribe_to_rooms( impl SlidingSyncInner { /// Send a message over the internal channel. - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] fn internal_channel_send(&self, message: SlidingSyncInternalMessage) -> Result<(), Error> { self.internal_channel.send(message).map(|_| ()).map_err(|_| Error::InternalChannelIsBroken) } /// Send a message over the internal channel if there is a receiver, i.e. if /// the sync loop is running. - #[instrument] + #[cfg_attr(feature = "instrument", tracing::instrument)] fn internal_channel_send_if_possible(&self, message: SlidingSyncInternalMessage) { // If there is no receiver, the send will fail, but that's OK here. let _ = self.internal_channel.send(message); diff --git a/crates/matrix-sdk/src/sync.rs b/crates/matrix-sdk/src/sync.rs index e21fff47e43..8b8395ee120 100644 --- a/crates/matrix-sdk/src/sync.rs +++ b/crates/matrix-sdk/src/sync.rs @@ -41,7 +41,7 @@ use ruma::{ serde::Raw, time::Instant, }; -use tracing::{debug, error, instrument, warn}; +use tracing::{debug, error, warn}; use crate::{Client, Result, Room, event_handler::HandlerKind}; @@ -354,7 +354,7 @@ impl Client { /// /// That way, the latest event is computed and updated for all rooms receiving /// an update from the sync. -#[instrument(skip_all)] +#[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] pub(crate) async fn subscribe_to_room_latest_events<'a, R>(client: &'a Client, room_ids: R) where R: Iterator, diff --git a/crates/matrix-sdk/src/widget/machine/mod.rs b/crates/matrix-sdk/src/widget/machine/mod.rs index c3543299ecd..f58630d2882 100644 --- a/crates/matrix-sdk/src/widget/machine/mod.rs +++ b/crates/matrix-sdk/src/widget/machine/mod.rs @@ -27,7 +27,7 @@ use ruma::{ use serde::Serialize; use serde_json::value::RawValue as RawJsonValue; use to_widget::NotifyNewToDeviceMessage; -use tracing::{error, info, instrument, warn}; +use tracing::{error, info, warn}; use uuid::Uuid; use self::{ @@ -271,7 +271,7 @@ impl WidgetMachine { } } - #[instrument(skip_all, fields(?request_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?request_id)))] fn process_from_widget_request( &mut self, request_id: String, @@ -545,7 +545,7 @@ impl WidgetMachine { Some(action) } - #[instrument(skip_all, fields(?request_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?request_id)))] fn process_to_widget_response( &mut self, request_id: String, @@ -578,7 +578,7 @@ impl WidgetMachine { .unwrap_or_default() } - #[instrument(skip_all, fields(?request_id))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(?request_id)))] fn process_matrix_driver_response( &mut self, request_id: Uuid, @@ -622,7 +622,7 @@ impl WidgetMachine { ) -> Action { // we do not want tho expose this to never allow sending arbitrary errors. // Errors always need to be `FromWidgetErrorResponse`. - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn send_response_data( raw_request: Raw, response_data: impl Serialize, @@ -648,7 +648,7 @@ impl WidgetMachine { } } - #[instrument(skip_all, fields(action = T::ACTION))] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all, fields(action = T::ACTION)))] fn send_to_widget_request( &mut self, to_widget_request: T, @@ -680,7 +680,7 @@ impl WidgetMachine { Some((ToWidgetRequestHandle::new(meta), Action::SendToWidget(serialized))) } - #[instrument(skip_all)] + #[cfg_attr(feature = "instrument", tracing::instrument(skip_all))] fn send_matrix_driver_request( &mut self, request: T, From 988c820079f25cbe988c1b88c34a723f10869339 Mon Sep 17 00:00:00 2001 From: Jakub Panek Date: Tue, 14 Apr 2026 19:16:38 +0200 Subject: [PATCH 2/2] fix: docs --- crates/matrix-sdk-crypto/src/machine/mod.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/matrix-sdk-crypto/src/machine/mod.rs b/crates/matrix-sdk-crypto/src/machine/mod.rs index 2ef57668780..94d90e5858e 100644 --- a/crates/matrix-sdk-crypto/src/machine/mod.rs +++ b/crates/matrix-sdk-crypto/src/machine/mod.rs @@ -293,7 +293,7 @@ impl OlmMachine { /// * `device_id` - The unique id of the device that owns this machine. /// /// * `store` - A `CryptoStore` implementation that will be used to store - /// the encryption keys. + /// the encryption keys. /// /// * `custom_account` - A custom [`vodozemac::olm::Account`] to be used for /// the identity and one-time keys of this [`OlmMachine`]. If no account @@ -2676,9 +2676,9 @@ impl OlmMachine { /// * `device_id` - The unique id of the device. /// /// * `timeout` - The amount of time we should wait before returning if the - /// user's device list has been marked as stale. **Note**, this assumes that - /// the requests from [`OlmMachine::outgoing_requests`] are being - /// processed and sent out. + /// user's device list has been marked as stale. **Note**, this assumes that + /// the requests from [`OlmMachine::outgoing_requests`] are being + /// processed and sent out. /// /// Returns a `Device` if one is found and the crypto store didn't throw an /// error. @@ -2714,9 +2714,9 @@ impl OlmMachine { /// * `user_id` - The unique id of the user that the identity belongs to /// /// * `timeout` - The amount of time we should wait before returning if the - /// user's device list has been marked as stale. **Note**, this assumes that - /// the requests from [`OlmMachine::outgoing_requests`] are being - /// processed and sent out. + /// user's device list has been marked as stale. **Note**, this assumes that + /// the requests from [`OlmMachine::outgoing_requests`] are being + /// processed and sent out. /// /// Returns a [`UserIdentity`] enum if one is found and the crypto store /// didn't throw an error. @@ -2737,9 +2737,9 @@ impl OlmMachine { /// * `user_id` - The unique id of the user that the devices belong to. /// /// * `timeout` - The amount of time we should wait before returning if the - /// user's device list has been marked as stale. **Note**, this assumes that - /// the requests from [`OlmMachine::outgoing_requests`] are being - /// processed and sent out. + /// user's device list has been marked as stale. **Note**, this assumes that + /// the requests from [`OlmMachine::outgoing_requests`] are being + /// processed and sent out. /// /// # Examples ///