Skip to content

Commit 3589ba6

Browse files
committed
chore(sdk): Use the root span in the sliding sync module as well
1 parent 1f74d7c commit 3589ba6

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
}
@@ -1035,6 +1036,7 @@ impl SlidingSync {
10351036
/// Create the inner stream for the view.
10361037
///
10371038
/// Run this stream to receive new updates from the server.
1039+
#[instrument(name = "sync_stream", skip_all, parent = &self.client.root_span)]
10381040
pub fn stream(&self) -> impl Stream<Item = Result<UpdateSummary, crate::Error>> + '_ {
10391041
let mut views = {
10401042
let mut views = BTreeMap::new();
@@ -1046,12 +1048,17 @@ impl SlidingSync {
10461048
};
10471049

10481050
debug!(?self.extensions, "Setting view stream going");
1051+
let stream_span = Span::current();
10491052

10501053
async_stream::stream! {
10511054
loop {
1052-
debug!(?self.extensions, "Sync loop running");
1055+
let sync_span = info_span!(parent: &stream_span, "sync_once");
10531056

1054-
match self.sync_once(&mut views).await {
1057+
sync_span.in_scope(|| {
1058+
debug!(?self.extensions, "Sync loop running");
1059+
});
1060+
1061+
match self.sync_once(&mut views).instrument(sync_span.clone()).await {
10551062
Ok(Some(updates)) => {
10561063
self.failure_count.store(0, Ordering::SeqCst);
10571064
yield Ok(updates)
@@ -1063,19 +1070,21 @@ impl SlidingSync {
10631070
if e.client_api_error_kind() == Some(&ErrorKind::UnknownPos) {
10641071
// session expired, let's reset
10651072
if self.failure_count.fetch_add(1, Ordering::SeqCst) >= 3 {
1066-
error!("session expired three times in a row");
1073+
sync_span.in_scope(|| error!("session expired three times in a row"));
10671074
yield Err(e.into());
10681075

10691076
break
10701077
}
10711078

1072-
warn!("Session expired. Restarting sliding sync.");
1073-
*self.pos.lock_mut() = None;
1079+
sync_span.in_scope(|| {
1080+
warn!("Session expired. Restarting sliding sync.");
1081+
*self.pos.lock_mut() = None;
10741082

1075-
// reset our extensions to the last known good ones.
1076-
*self.extensions.lock().unwrap() = self.sent_extensions.lock().unwrap().take();
1083+
// reset our extensions to the last known good ones.
1084+
*self.extensions.lock().unwrap() = self.sent_extensions.lock().unwrap().take();
10771085

1078-
debug!(?self.extensions, "Resetting view stream");
1086+
debug!(?self.extensions, "Resetting view stream");
1087+
});
10791088
}
10801089

10811090
yield Err(e.into());

0 commit comments

Comments
 (0)