Skip to content

Commit 9bd402a

Browse files
committed
chore(sdk): Use the root span in the sliding sync module as well
1 parent 2ab8e6a commit 9bd402a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

crates/matrix-sdk/src/sliding_sync.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use ruma::{
4545
};
4646
use serde::{Deserialize, Serialize};
4747
use thiserror::Error;
48-
use tracing::{debug, error, instrument, trace, warn};
48+
use tracing::{debug, error, info_span, instrument, trace, warn, Instrument, Span};
4949
use url::Url;
5050

5151
#[cfg(feature = "experimental-timeline")]
@@ -265,6 +265,7 @@ impl SlidingSyncRoom {
265265
/// Use `Timeline::latest_event` instead if you already have a timeline for
266266
/// this `SlidingSyncRoom`.
267267
#[cfg(feature = "experimental-timeline")]
268+
#[instrument(skip_all, parent = &self.client.root_span)]
268269
pub async fn latest_event(&self) -> Option<EventTimelineItem> {
269270
self.timeline_no_fully_read_tracking().await?.latest_event()
270271
}
@@ -1025,6 +1026,7 @@ impl SlidingSync {
10251026
/// Create the inner stream for the view.
10261027
///
10271028
/// Run this stream to receive new updates from the server.
1029+
#[instrument(name = "sync_stream", skip_all, parent = &self.client.root_span)]
10281030
pub fn stream(&self) -> impl Stream<Item = Result<UpdateSummary, crate::Error>> + '_ {
10291031
let mut views = {
10301032
let mut views = BTreeMap::new();
@@ -1036,12 +1038,17 @@ impl SlidingSync {
10361038
};
10371039

10381040
debug!(?self.extensions, "Setting view stream going");
1041+
let stream_span = Span::current();
10391042

10401043
async_stream::stream! {
10411044
loop {
1042-
debug!(?self.extensions, "Sync loop running");
1045+
let sync_span = info_span!(parent: &stream_span, "sync_once");
10431046

1044-
match self.sync_once(&mut views).await {
1047+
sync_span.in_scope(|| {
1048+
debug!(?self.extensions, "Sync loop running");
1049+
});
1050+
1051+
match self.sync_once(&mut views).instrument(sync_span.clone()).await {
10451052
Ok(Some(updates)) => {
10461053
self.failure_count.store(0, Ordering::SeqCst);
10471054
yield Ok(updates)
@@ -1053,19 +1060,21 @@ impl SlidingSync {
10531060
if e.client_api_error_kind() == Some(&ErrorKind::UnknownPos) {
10541061
// session expired, let's reset
10551062
if self.failure_count.fetch_add(1, Ordering::SeqCst) >= 3 {
1056-
error!("session expired three times in a row");
1063+
sync_span.in_scope(|| error!("session expired three times in a row"));
10571064
yield Err(e.into());
10581065

10591066
break
10601067
}
10611068

1062-
warn!("Session expired. Restarting sliding sync.");
1063-
*self.pos.lock_mut() = None;
1069+
sync_span.in_scope(|| {
1070+
warn!("Session expired. Restarting sliding sync.");
1071+
*self.pos.lock_mut() = None;
10641072

1065-
// reset our extensions to the last known good ones.
1066-
*self.extensions.lock().unwrap() = self.sent_extensions.lock().unwrap().take();
1073+
// reset our extensions to the last known good ones.
1074+
*self.extensions.lock().unwrap() = self.sent_extensions.lock().unwrap().take();
10671075

1068-
debug!(?self.extensions, "Resetting view stream");
1076+
debug!(?self.extensions, "Resetting view stream");
1077+
});
10691078
}
10701079

10711080
yield Err(e.into());

0 commit comments

Comments
 (0)