@@ -35,6 +35,8 @@ use tokio::signal::unix::{signal, SignalKind};
3535#[ cfg( feature = "expose-metrics" ) ]
3636use std:: time:: Instant ;
3737
38+ #[ cfg( feature = "expose-metrics" ) ]
39+ use http:: header:: CONTENT_TYPE ;
3840#[ cfg( feature = "expose-metrics" ) ]
3941use lazy_static:: lazy_static;
4042#[ cfg( feature = "expose-metrics" ) ]
@@ -98,7 +100,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
98100 )
99101 . build_recorder ( ) ;
100102 handle = Arc :: new ( recorder. handle ( ) ) ;
101- metrics:: set_boxed_recorder ( Box :: new ( recorder) )
103+ metrics:: set_global_recorder ( Box :: new ( recorder) )
102104 . expect ( "Failed to create metrics receiver!" ) ;
103105 }
104106
@@ -401,7 +403,8 @@ async fn handle_request(
401403 . and_then ( |header| header. to_str ( ) . ok ( ) )
402404 . unwrap_or ( "" )
403405 . to_string ( ) ;
404- histogram ! ( METRIC_KEY . as_str( ) , end - start, "method" =>m. to_string( ) , "route" =>p, "status" =>status. to_string( ) , "scope" => scope) ;
406+ histogram ! ( METRIC_KEY . as_str( ) , "method" =>m. to_string( ) , "route" =>p, "status" =>status. to_string( ) , "scope" => scope)
407+ . record ( end - start) ;
405408 }
406409
407410 debug ! ( "{} {} ({}): {}" , m, p, request_path, status) ;
@@ -412,6 +415,10 @@ async fn handle_request(
412415#[ cfg( feature = "expose-metrics" ) ]
413416fn handle_metrics ( handle : Arc < PrometheusHandle > ) -> Response < Body > {
414417 Response :: builder ( )
418+ . header (
419+ CONTENT_TYPE ,
420+ HeaderValue :: from_static ( "text/plain; version=0.0.4" ) ,
421+ )
415422 . body ( Body :: from ( handle. render ( ) ) )
416423 . unwrap ( )
417424}
0 commit comments