@@ -24,6 +24,7 @@ use std::fmt::Display;
2424use std:: future:: Future ;
2525use std:: io;
2626use std:: net:: SocketAddr ;
27+ use std:: num:: NonZeroU32 ;
2728use std:: str:: FromStr ;
2829use std:: sync:: atomic:: AtomicUsize ;
2930use std:: sync:: atomic:: Ordering ;
@@ -56,7 +57,7 @@ use crate::prepared_statement::{PartitionKeyError, PreparedStatement};
5657use crate :: query:: Query ;
5758use crate :: routing:: Token ;
5859use crate :: statement:: { Consistency , SerialConsistency } ;
59- use crate :: tracing:: { GetTracingConfig , TracingEvent , TracingInfo } ;
60+ use crate :: tracing:: { TracingEvent , TracingInfo } ;
6061use crate :: transport:: cluster:: { Cluster , ClusterData , ClusterNeatDebug } ;
6162use crate :: transport:: connection:: { Connection , ConnectionConfig , VerifiedKeyspaceName } ;
6263use crate :: transport:: connection_pool:: PoolConfig ;
@@ -130,6 +131,9 @@ pub struct Session {
130131 auto_await_schema_agreement_timeout : Option < Duration > ,
131132 refresh_metadata_on_auto_schema_agreement : bool ,
132133 keyspace_name : ArcSwapOption < String > ,
134+ tracing_info_fetch_attempts : NonZeroU32 ,
135+ tracing_info_fetch_interval : Duration ,
136+ tracing_info_fetch_consistency : Consistency ,
133137}
134138
135139/// This implementation deliberately omits some details from Cluster in order
@@ -235,6 +239,22 @@ pub struct SessionConfig {
235239 /// Please do performance measurements before committing to disabling
236240 /// this option.
237241 pub enable_write_coalescing : bool ,
242+
243+ /// Number of attempts to fetch [`TracingInfo`]
244+ /// in [`Session::get_tracing_info`]. Tracing info
245+ /// might not be available immediately on queried node - that's why
246+ /// the driver performs a few attempts with sleeps in between.
247+ pub tracing_info_fetch_attempts : NonZeroU32 ,
248+
249+ /// Delay between attempts to fetch [`TracingInfo`]
250+ /// in [`Session::get_tracing_info`]. Tracing info
251+ /// might not be available immediately on queried node - that's why
252+ /// the driver performs a few attempts with sleeps in between.
253+ pub tracing_info_fetch_interval : Duration ,
254+
255+ /// Consistency level of fetching [`TracingInfo`]
256+ /// in [`Session::get_tracing_info`].
257+ pub tracing_info_fetch_consistency : Consistency ,
238258}
239259
240260/// Describes database server known on Session startup.
@@ -294,6 +314,9 @@ impl SessionConfig {
294314 #[ cfg( feature = "cloud" ) ]
295315 cloud_config : None ,
296316 enable_write_coalescing : true ,
317+ tracing_info_fetch_attempts : NonZeroU32 :: new ( 5 ) . unwrap ( ) ,
318+ tracing_info_fetch_interval : Duration :: from_millis ( 3 ) ,
319+ tracing_info_fetch_consistency : Consistency :: One ,
297320 }
298321 }
299322
@@ -544,6 +567,9 @@ impl Session {
544567 refresh_metadata_on_auto_schema_agreement : config
545568 . refresh_metadata_on_auto_schema_agreement ,
546569 keyspace_name : ArcSwapOption :: default ( ) , // will be set by use_keyspace
570+ tracing_info_fetch_attempts : config. tracing_info_fetch_attempts ,
571+ tracing_info_fetch_interval : config. tracing_info_fetch_interval ,
572+ tracing_info_fetch_consistency : config. tracing_info_fetch_consistency ,
547573 } ;
548574
549575 if let Some ( keyspace_name) = config. used_keyspace {
@@ -1337,8 +1363,24 @@ impl Session {
13371363 /// See [the book](https://rust-driver.docs.scylladb.com/stable/tracing/tracing.html)
13381364 /// for more information about query tracing
13391365 pub async fn get_tracing_info ( & self , tracing_id : & Uuid ) -> Result < TracingInfo , QueryError > {
1340- self . get_tracing_info_custom ( tracing_id, & GetTracingConfig :: default ( ) )
1341- . await
1366+ // tracing_info_fetch_attempts is NonZeroU32 so at least one attempt will be made
1367+ for _ in 0 ..self . tracing_info_fetch_attempts . get ( ) {
1368+ let current_try: Option < TracingInfo > = self
1369+ . try_getting_tracing_info ( tracing_id, Some ( self . tracing_info_fetch_consistency ) )
1370+ . await ?;
1371+
1372+ match current_try {
1373+ Some ( tracing_info) => return Ok ( tracing_info) ,
1374+ None => tokio:: time:: sleep ( self . tracing_info_fetch_interval ) . await ,
1375+ } ;
1376+ }
1377+
1378+ Err ( QueryError :: ProtocolError (
1379+ "All tracing queries returned an empty result, \
1380+ maybe the trace information didn't propagate yet. \
1381+ Consider configuring Session with \
1382+ a longer fetch interval (tracing_info_fetch_interval)",
1383+ ) )
13421384 }
13431385
13441386 /// Gets the name of the keyspace that is currently set, or `None` if no
@@ -1356,35 +1398,6 @@ impl Session {
13561398 self . keyspace_name . load_full ( )
13571399 }
13581400
1359- /// Queries tracing info with custom retry settings.\
1360- /// Tracing info might not be available immediately on queried node -
1361- /// that's why the driver performs a few attempts with sleeps in between.
1362- /// [`GetTracingConfig`] allows to specify a custom querying strategy.
1363- pub async fn get_tracing_info_custom (
1364- & self ,
1365- tracing_id : & Uuid ,
1366- config : & GetTracingConfig ,
1367- ) -> Result < TracingInfo , QueryError > {
1368- // config.attempts is NonZeroU32 so at least one attempt will be made
1369- for _ in 0 ..config. attempts . get ( ) {
1370- let current_try: Option < TracingInfo > = self
1371- . try_getting_tracing_info ( tracing_id, Some ( config. consistency ) )
1372- . await ?;
1373-
1374- match current_try {
1375- Some ( tracing_info) => return Ok ( tracing_info) ,
1376- None => tokio:: time:: sleep ( config. interval ) . await ,
1377- } ;
1378- }
1379-
1380- Err ( QueryError :: ProtocolError (
1381- "All tracing queries returned an empty result, \
1382- maybe information didn't reach this node yet. \
1383- Consider using get_tracing_info_custom with \
1384- bigger interval in GetTracingConfig",
1385- ) )
1386- }
1387-
13881401 // Tries getting the tracing info
13891402 // If the queries return 0 rows then returns None - the information didn't reach this node yet
13901403 // If there is some other error returns this error
0 commit comments