11use axum:: {
2+ body:: HttpBody ,
23 extract:: { DefaultBodyLimit , MatchedPath , Request } ,
34 middleware:: { self , Next } ,
45 response:: Response ,
@@ -10,7 +11,7 @@ use cb_common::pbs::{
1011 BUILDER_V1_API_PATH , BUILDER_V2_API_PATH , GET_HEADER_PATH , GET_STATUS_PATH ,
1112 REGISTER_VALIDATOR_PATH , RELOAD_PATH , SUBMIT_BLOCK_PATH ,
1213} ;
13- use tracing:: trace;
14+ use tracing:: { trace, warn } ;
1415use uuid:: Uuid ;
1516
1617use super :: {
@@ -75,6 +76,8 @@ pub fn create_app_router<S: BuilderApiState, A: BuilderApi<S>>(state: PbsStateGu
7576 ) ,
7677) ]
7778pub async fn tracing_middleware ( req : Request , next : Next ) -> Response {
79+ let mut watcher = RequestWatcher :: new ( ) ;
80+
7881 trace ! (
7982 http. method = %req. method( ) ,
8083 http. user_agent = req. headers( ) . typed_get:: <UserAgent >( ) . map( |ua| ua. to_string( ) ) . unwrap_or_default( ) ,
@@ -84,8 +87,32 @@ pub async fn tracing_middleware(req: Request, next: Next) -> Response {
8487 let response = next. run ( req) . await ;
8588
8689 let status = response. status ( ) ;
90+ let response_size = response. body ( ) . size_hint ( ) . upper ( ) . unwrap_or ( 0 ) ;
8791
88- trace ! ( http. response. status_code = ?status, "end request" ) ;
92+ trace ! ( http. response. status_code = ?status, response_size , "end request" ) ;
8993
94+ watcher. observe ( ) ;
9095 response
9196}
97+
98+ struct RequestWatcher {
99+ observed : bool ,
100+ }
101+
102+ impl RequestWatcher {
103+ fn new ( ) -> Self {
104+ Self { observed : false }
105+ }
106+
107+ fn observe ( & mut self ) {
108+ self . observed = true ;
109+ }
110+ }
111+
112+ impl Drop for RequestWatcher {
113+ fn drop ( & mut self ) {
114+ if !self . observed {
115+ warn ! ( "client timed out" )
116+ }
117+ }
118+ }
0 commit comments