@@ -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, 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 {
@@ -1142,6 +1143,15 @@ impl Client {
1142
1143
}
1143
1144
}
1144
1145
1146
+ self . root_span
1147
+ . record ( "user_id" , display ( & response. user_id ) )
1148
+ . record ( "device_id" , display ( & response. device_id ) ) ;
1149
+
1150
+ #[ cfg( feature = "e2e-encryption" ) ]
1151
+ if let Some ( key) = self . encryption ( ) . ed25519_key ( ) . await {
1152
+ self . root_span . record ( "ed25519_key" , key) ;
1153
+ }
1154
+
1145
1155
self . inner . base_client . receive_login_response ( response) . await ?;
1146
1156
1147
1157
Ok ( ( ) )
@@ -1206,10 +1216,27 @@ impl Client {
1206
1216
/// ```
1207
1217
///
1208
1218
/// [`login`]: #method.login
1219
+ #[ instrument( skip_all, parent = & self . root_span) ]
1209
1220
pub async fn restore_session ( & self , session : Session ) -> Result < ( ) > {
1221
+ debug ! ( "Restoring session" ) ;
1222
+
1210
1223
let ( meta, tokens) = session. into_parts ( ) ;
1224
+
1225
+ self . root_span
1226
+ . record ( "user_id" , display ( & meta. user_id ) )
1227
+ . record ( "device_id" , display ( & meta. device_id ) ) ;
1228
+
1211
1229
self . base_client ( ) . set_session_tokens ( tokens) ;
1212
- Ok ( self . base_client ( ) . set_session_meta ( meta) . await ?)
1230
+ self . base_client ( ) . set_session_meta ( meta) . await ?;
1231
+
1232
+ #[ cfg( feature = "e2e-encryption" ) ]
1233
+ if let Some ( key) = self . encryption ( ) . ed25519_key ( ) . await {
1234
+ self . root_span . record ( "ed25519_key" , key) ;
1235
+ }
1236
+
1237
+ debug ! ( "Done restoring session" ) ;
1238
+
1239
+ Ok ( ( ) )
1213
1240
}
1214
1241
1215
1242
/// Refresh the access token.
@@ -1391,7 +1418,7 @@ impl Client {
1391
1418
/// client.register(request).await;
1392
1419
/// # })
1393
1420
/// ```
1394
- #[ instrument( skip_all) ]
1421
+ #[ instrument( skip_all, parent = & self . root_span ) ]
1395
1422
pub async fn register (
1396
1423
& self ,
1397
1424
request : register:: v3:: Request ,
@@ -1454,7 +1481,7 @@ impl Client {
1454
1481
///
1455
1482
/// let response = client.sync_once(sync_settings).await.unwrap();
1456
1483
/// # });
1457
- #[ instrument( skip( self , definition) ) ]
1484
+ #[ instrument( skip( self , definition) , parent = & self . root_span ) ]
1458
1485
pub async fn get_or_upload_filter (
1459
1486
& self ,
1460
1487
filter_name : & str ,
@@ -2147,7 +2174,7 @@ impl Client {
2147
2174
/// .await;
2148
2175
/// })
2149
2176
/// ```
2150
- #[ instrument( skip ( self , callback ) ) ]
2177
+ #[ instrument( skip_all , parent = & self . root_span ) ]
2151
2178
pub async fn sync_with_callback < C > (
2152
2179
& self ,
2153
2180
sync_settings : crate :: config:: SyncSettings ,
@@ -2244,11 +2271,15 @@ impl Client {
2244
2271
}
2245
2272
2246
2273
loop {
2274
+ debug ! ( "Syncing" ) ;
2247
2275
let result = self . sync_loop_helper ( & mut sync_settings) . await ;
2248
2276
2277
+ debug ! ( "Running callback" ) ;
2249
2278
if callback ( result) . await ? == LoopCtrl :: Break {
2279
+ debug ! ( "Callback told us to stop" ) ;
2250
2280
break ;
2251
2281
}
2282
+ debug ! ( "Done running callback" ) ;
2252
2283
2253
2284
Client :: delay_sync ( & mut last_sync_time) . await
2254
2285
}
@@ -2298,7 +2329,7 @@ impl Client {
2298
2329
///
2299
2330
/// # anyhow::Ok(()) });
2300
2331
/// ```
2301
- #[ instrument( skip( self ) ) ]
2332
+ #[ instrument( skip( self ) , parent = & self . root_span ) ]
2302
2333
pub async fn sync_stream (
2303
2334
& self ,
2304
2335
mut sync_settings : crate :: config:: SyncSettings ,
0 commit comments