@@ -3,6 +3,8 @@ use std::{borrow::Cow, sync::Arc};
3
3
use futures_core:: future:: BoxFuture ;
4
4
use futures_util:: FutureExt ;
5
5
use mysql_common:: constants:: Command ;
6
+ #[ cfg( feature = "tracing" ) ]
7
+ use tracing:: { field, info_span, Instrument , Level , Span } ;
6
8
7
9
use crate :: { queryable:: stmt:: StmtInner , Conn } ;
8
10
@@ -24,12 +26,30 @@ impl PrepareRoutine {
24
26
25
27
impl Routine < Arc < StmtInner > > for PrepareRoutine {
26
28
fn call < ' a > ( & ' a mut self , conn : & ' a mut Conn ) -> BoxFuture < ' a , crate :: Result < Arc < StmtInner > > > {
27
- async move {
29
+ #[ cfg( feature = "tracing" ) ]
30
+ let span = info_span ! (
31
+ "mysql_async::prepare" ,
32
+ mysql_async. connection. id = conn. id( ) ,
33
+ mysql_async. statement. id = field:: Empty ,
34
+ mysql_async. query. sql = field:: Empty ,
35
+ ) ;
36
+ #[ cfg( feature = "tracing" ) ]
37
+ if tracing:: span_enabled!( Level :: DEBUG ) {
38
+ // The statement may contain sensitive data. Restrict to DEBUG.
39
+ span. record (
40
+ "mysql_async.query.sql" ,
41
+ String :: from_utf8_lossy ( & * self . query ) . as_ref ( ) ,
42
+ ) ;
43
+ }
44
+
45
+ let fut = async move {
28
46
conn. write_command_data ( Command :: COM_STMT_PREPARE , & self . query )
29
47
. await ?;
30
48
31
49
let packet = conn. read_packet ( ) . await ?;
32
50
let mut inner_stmt = StmtInner :: from_payload ( & * packet, conn. id ( ) , self . query . clone ( ) ) ?;
51
+ #[ cfg( feature = "tracing" ) ]
52
+ Span :: current ( ) . record ( "mysql_async.statement.id" , inner_stmt. id ( ) ) ;
33
53
34
54
if inner_stmt. num_params ( ) > 0 {
35
55
let params = conn. read_column_defs ( inner_stmt. num_params ( ) ) . await ?;
@@ -42,7 +62,11 @@ impl Routine<Arc<StmtInner>> for PrepareRoutine {
42
62
}
43
63
44
64
Ok ( Arc :: new ( inner_stmt) )
45
- }
46
- . boxed ( )
65
+ } ;
66
+
67
+ #[ cfg( feature = "tracing" ) ]
68
+ let fut = fut. instrument ( span) ;
69
+
70
+ fut. boxed ( )
47
71
}
48
72
}
0 commit comments