File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use tonic::metadata::BinaryMetadataValue;
1010
1111use crate :: auth:: Authenticated ;
1212use crate :: error:: Error ;
13+ use crate :: http:: user:: timing:: sample_time;
1314use crate :: metrics:: {
1415 CONCURRENT_CONNECTIONS_COUNT , CONNECTION_ALIVE_DURATION , CONNECTION_CREATE_TIME ,
1516} ;
@@ -398,6 +399,7 @@ pub struct TrackedConnection<DB> {
398399
399400impl < T > Drop for TrackedConnection < T > {
400401 fn drop ( & mut self ) {
402+ sample_time ( "connection-duration" , self . created_at . elapsed ( ) ) ;
401403 CONCURRENT_CONNECTIONS_COUNT . decrement ( 1.0 ) ;
402404 CONNECTION_ALIVE_DURATION . record ( self . created_at . elapsed ( ) ) ;
403405 }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use axum::middleware::Next;
77use axum:: response:: Response ;
88use hashbrown:: HashMap ;
99use parking_lot:: Mutex ;
10+ use tracing:: { Instrument , Span } ;
1011
1112#[ derive( Default , Clone , Debug ) ]
1213pub struct Timings {
@@ -40,13 +41,22 @@ macro_rules! record_time {
4041 let __ret__ = {
4142 $( $rest) *
4243 } ;
43- let _ = $crate:: http:: user:: timing:: TIMINGS . try_with( |t| t. record( $k, __before__. elapsed( ) ) ) ;
44+ let __elapsed__ = __before__. elapsed( ) ;
45+ tracing:: debug!( target: "timings" , name = $k, elapsed = tracing:: field:: debug( __elapsed__) ) ;
46+ let _ = $crate:: http:: user:: timing:: TIMINGS . try_with( |t| t. record( $k, __elapsed__) ) ;
4447 __ret__
4548 }
4649 } ;
4750}
4851
52+ pub fn sample_time ( name : & ' static str , duration : Duration ) {
53+ tracing:: debug!( target: "timings" , name = name, elapsed = tracing:: field:: debug( duration) ) ;
54+ let _ = TIMINGS . try_with ( |t| t. record ( name, duration) ) ;
55+ }
56+
57+ #[ tracing:: instrument( skip_all, fields( req_id = tracing:: field:: debug( uuid:: Uuid :: new_v4( ) ) ) ) ]
4958pub ( crate ) async fn timings_middleware < B > ( request : Request < B > , next : Next < B > ) -> Response {
59+ // tracing::error!("hello");
5060 TIMINGS
5161 . scope ( Default :: default ( ) , async move {
5262 let mut response = record_time ! {
You can’t perform that action at this time.
0 commit comments