@@ -69,7 +69,7 @@ use serde::de::DeserializeOwned;
69
69
use tokio:: sync:: OnceCell ;
70
70
#[ cfg( feature = "e2e-encryption" ) ]
71
71
use tracing:: error;
72
- use tracing:: { debug, info, instrument} ;
72
+ use tracing:: { debug, field :: display , info, instrument, trace , Instrument , Span } ;
73
73
use url:: Url ;
74
74
75
75
#[ cfg( feature = "e2e-encryption" ) ]
@@ -128,6 +128,7 @@ pub enum LoopCtrl {
128
128
#[ derive( Clone ) ]
129
129
pub struct Client {
130
130
pub ( crate ) inner : Arc < ClientInner > ,
131
+ pub ( crate ) root_span : Span ,
131
132
}
132
133
133
134
pub ( crate ) struct ClientInner {
@@ -1152,6 +1153,15 @@ impl Client {
1152
1153
}
1153
1154
}
1154
1155
1156
+ self . root_span
1157
+ . record ( "user_id" , display ( & response. user_id ) )
1158
+ . record ( "device_id" , display ( & response. device_id ) ) ;
1159
+
1160
+ #[ cfg( feature = "e2e-encryption" ) ]
1161
+ if let Some ( key) = self . encryption ( ) . ed25519_key ( ) . await {
1162
+ self . root_span . record ( "ed25519_key" , key) ;
1163
+ }
1164
+
1155
1165
self . inner . base_client . receive_login_response ( response) . await ?;
1156
1166
1157
1167
Ok ( ( ) )
@@ -1216,10 +1226,27 @@ impl Client {
1216
1226
/// ```
1217
1227
///
1218
1228
/// [`login`]: #method.login
1229
+ #[ instrument( skip_all, parent = & self . root_span) ]
1219
1230
pub async fn restore_session ( & self , session : Session ) -> Result < ( ) > {
1231
+ debug ! ( "Restoring session" ) ;
1232
+
1220
1233
let ( meta, tokens) = session. into_parts ( ) ;
1234
+
1235
+ self . root_span
1236
+ . record ( "user_id" , display ( & meta. user_id ) )
1237
+ . record ( "device_id" , display ( & meta. device_id ) ) ;
1238
+
1221
1239
self . base_client ( ) . set_session_tokens ( tokens) ;
1222
- Ok ( self . base_client ( ) . set_session_meta ( meta) . await ?)
1240
+ self . base_client ( ) . set_session_meta ( meta) . await ?;
1241
+
1242
+ #[ cfg( feature = "e2e-encryption" ) ]
1243
+ if let Some ( key) = self . encryption ( ) . ed25519_key ( ) . await {
1244
+ self . root_span . record ( "ed25519_key" , key) ;
1245
+ }
1246
+
1247
+ debug ! ( "Done restoring session" ) ;
1248
+
1249
+ Ok ( ( ) )
1223
1250
}
1224
1251
1225
1252
/// Refresh the access token.
@@ -1401,7 +1428,7 @@ impl Client {
1401
1428
/// client.register(request).await;
1402
1429
/// # })
1403
1430
/// ```
1404
- #[ instrument( skip_all) ]
1431
+ #[ instrument( skip_all, parent = & self . root_span ) ]
1405
1432
pub async fn register (
1406
1433
& self ,
1407
1434
request : register:: v3:: Request ,
@@ -1464,7 +1491,7 @@ impl Client {
1464
1491
///
1465
1492
/// let response = client.sync_once(sync_settings).await.unwrap();
1466
1493
/// # });
1467
- #[ instrument( skip( self , definition) ) ]
1494
+ #[ instrument( skip( self , definition) , parent = & self . root_span ) ]
1468
1495
pub async fn get_or_upload_filter (
1469
1496
& self ,
1470
1497
filter_name : & str ,
@@ -2157,7 +2184,7 @@ impl Client {
2157
2184
/// .await;
2158
2185
/// })
2159
2186
/// ```
2160
- #[ instrument( skip ( self , callback ) ) ]
2187
+ #[ instrument( skip_all , parent = & self . root_span ) ]
2161
2188
pub async fn sync_with_callback < C > (
2162
2189
& self ,
2163
2190
sync_settings : crate :: config:: SyncSettings ,
@@ -2254,11 +2281,15 @@ impl Client {
2254
2281
}
2255
2282
2256
2283
loop {
2284
+ trace ! ( "Syncing" ) ;
2257
2285
let result = self . sync_loop_helper ( & mut sync_settings) . await ;
2258
2286
2287
+ trace ! ( "Running callback" ) ;
2259
2288
if callback ( result) . await ? == LoopCtrl :: Break {
2289
+ trace ! ( "Callback told us to stop" ) ;
2260
2290
break ;
2261
2291
}
2292
+ trace ! ( "Done running callback" ) ;
2262
2293
2263
2294
Client :: delay_sync ( & mut last_sync_time) . await
2264
2295
}
@@ -2308,7 +2339,7 @@ impl Client {
2308
2339
///
2309
2340
/// # anyhow::Ok(()) });
2310
2341
/// ```
2311
- #[ instrument( skip( self ) ) ]
2342
+ #[ instrument( skip( self ) , parent = & self . root_span ) ]
2312
2343
pub async fn sync_stream (
2313
2344
& self ,
2314
2345
mut sync_settings : crate :: config:: SyncSettings ,
@@ -2319,9 +2350,11 @@ impl Client {
2319
2350
sync_settings. token = self . sync_token ( ) . await ;
2320
2351
}
2321
2352
2353
+ let parent_span = Span :: current ( ) ;
2354
+
2322
2355
async_stream:: stream! {
2323
2356
loop {
2324
- yield self . sync_loop_helper( & mut sync_settings) . await ;
2357
+ yield self . sync_loop_helper( & mut sync_settings) . instrument ( parent_span . clone ( ) ) . await ;
2325
2358
2326
2359
Client :: delay_sync( & mut last_sync_time) . await
2327
2360
}
0 commit comments