File tree 4 files changed +20
-1
lines changed
4 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ use opensrv_mysql::InitWriter;
45
45
use opensrv_mysql:: ParamParser ;
46
46
use opensrv_mysql:: QueryResultWriter ;
47
47
use opensrv_mysql:: StatementMetaWriter ;
48
+ use rand:: thread_rng;
49
+ use rand:: Rng as _;
48
50
use rand:: RngCore ;
49
51
use uuid:: Uuid ;
50
52
@@ -192,7 +194,9 @@ impl<W: AsyncWrite + Send + Sync + Unpin> AsyncMysqlShim<W> for InteractiveWorke
192
194
writer : QueryResultWriter < ' a , W > ,
193
195
) -> Result < ( ) > {
194
196
let query_id = Uuid :: new_v4 ( ) . to_string ( ) ;
195
- let root = Span :: root ( func_path ! ( ) , SpanContext :: random ( ) )
197
+ let sampled =
198
+ thread_rng ( ) . gen_range ( 0 ..100 ) <= self . base . session . get_trace_sample_rate ( ) ?;
199
+ let root = Span :: root ( func_path ! ( ) , SpanContext :: random ( ) . sampled ( sampled) )
196
200
. with_properties ( || self . base . session . to_fastrace_properties ( ) ) ;
197
201
198
202
let mut tracking_payload = ThreadTracker :: new_tracking_payload ( ) ;
Original file line number Diff line number Diff line change @@ -388,6 +388,10 @@ impl Session {
388
388
self . session_ctx . set_temp_tbl_mgr ( temp_tbl_mgr)
389
389
}
390
390
391
+ pub fn get_trace_sample_rate ( & self ) -> Result < u64 > {
392
+ self . session_ctx . get_settings ( ) . get_trace_sample_rate ( )
393
+ }
394
+
391
395
pub fn set_query_priority ( & self , priority : u8 ) {
392
396
if let Some ( context_shared) = self . session_ctx . get_query_context_shared ( ) {
393
397
context_shared. set_priority ( priority) ;
Original file line number Diff line number Diff line change @@ -1271,6 +1271,13 @@ impl DefaultSettings {
1271
1271
scope : SettingScope :: Both ,
1272
1272
range : Some ( SettingRange :: Numeric ( 0 ..=1 ) ) ,
1273
1273
} ) ,
1274
+ ( "trace_sample_rate" , DefaultSettingValue {
1275
+ value : UserSettingValue :: UInt64 ( 1 ) ,
1276
+ desc : "Setting the trace sample rate. The value should be between '0' and '100'" ,
1277
+ mode : SettingMode :: Both ,
1278
+ scope : SettingScope :: Both ,
1279
+ range : Some ( SettingRange :: Numeric ( 0 ..=100 ) ) ,
1280
+ } ) ,
1274
1281
] ) ;
1275
1282
1276
1283
Ok ( Arc :: new ( DefaultSettings {
Original file line number Diff line number Diff line change @@ -936,4 +936,8 @@ impl Settings {
936
936
pub fn get_statement_queue_ttl_in_seconds ( & self ) -> Result < u64 > {
937
937
self . try_get_u64 ( "statement_queue_ttl_in_seconds" )
938
938
}
939
+
940
+ pub fn get_trace_sample_rate ( & self ) -> Result < u64 > {
941
+ self . try_get_u64 ( "trace_sample_rate" )
942
+ }
939
943
}
You can’t perform that action at this time.
0 commit comments