Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/matrix-sdk-base/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use ruma::{
events::{AnyRoomAccountDataEvent, marked_unread::MarkedUnreadEventContent},
serde::Raw,
};
use tracing::{instrument, warn};
use tracing::warn;

use super::super::{Context, RoomInfoNotableUpdates};
use crate::{
RoomInfo, RoomInfoNotableUpdateReasons, StateChanges, room::AccountDataSource,
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,
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/response_processors/changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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");

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<U>(
context: &mut Context,
raw_events: Vec<RawStateEventWithKeys<AnySyncStateEvent>>,
Expand Down Expand Up @@ -268,7 +267,6 @@ pub mod stripped {
events::{AnyStrippedStateEvent, StateEventType},
push::Action,
};
use tracing::instrument;

use super::{
super::{notification, timeline},
Expand Down Expand Up @@ -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<RawStateEventWithKeys<AnyStrippedStateEvent>>,
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/response_processors/timeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/room/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<bool> {
match self.state() {
RoomState::Joined | RoomState::Left | RoomState::Banned => {
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/room/room_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<DynStateStore>) -> bool {
let mut migrated = false;

Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/sliding_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-base/src/store/ambiguity_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -79,7 +79,7 @@ pub(crate) struct AmbiguityCache {
pub changes: BTreeMap<OwnedRoomId, BTreeMap<OwnedEventId, AmbiguityChange>>,
}

#[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<OwnedUserId>,
Expand Down
6 changes: 3 additions & 3 deletions crates/matrix-sdk-base/src/store/memory_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions crates/matrix-sdk-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions crates/matrix-sdk-common/src/cross_process_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<L::LockError> {
// If it's not `MultiProcess`, this behaves as a no-op
let CrossProcessLockConfig::MultiProcess { holder_name } = &self.config else {
Expand Down Expand Up @@ -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<u32>,
Expand Down
3 changes: 3 additions & 0 deletions crates/matrix-sdk-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/matrix-sdk-crypto/src/backups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");

Expand Down
7 changes: 5 additions & 2 deletions crates/matrix-sdk-crypto/src/gossiping/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions crates/matrix-sdk-crypto/src/identities/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading
Loading