File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
kms-connector/crates/utils/src/monitoring Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 1- use actix_web:: { HttpResponse , http:: StatusCode } ;
1+ use actix_web:: { HttpResponse , HttpResponseBuilder , body :: BoxBody , http:: StatusCode } ;
22use anyhow:: anyhow;
33use opentelemetry:: {
44 global,
@@ -51,13 +51,20 @@ pub fn init_otlp_setup(service_name: String) -> anyhow::Result<()> {
5151 Ok ( ( ) )
5252}
5353
54+ /// The content type header for Prometheus text-based metrics format.
55+ ///
56+ /// For more details, check https://prometheus.io/docs/instrumenting/exposition_formats/#text-based-format
57+ const PROMETHEUS_TEXT_FORMAT_HEADER : ( & str , & str ) = ( "Content-Type" , "text/plain; version=0.0.4" ) ;
58+
5459/// Responder used to collect metrics of the service.
5560pub async fn metrics_responder ( ) -> impl actix_web:: Responder {
5661 let encoder = prometheus:: TextEncoder :: new ( ) ;
5762 let metric_families = prometheus:: gather ( ) ;
5863 match encoder. encode_to_string ( & metric_families) {
59- Ok ( encoded_metrics) => HttpResponse :: with_body ( StatusCode :: OK , encoded_metrics) ,
60- Err ( e) => HttpResponse :: with_body ( StatusCode :: INTERNAL_SERVER_ERROR , e. to_string ( ) ) ,
64+ Ok ( encoded_metrics) => HttpResponse :: Ok ( )
65+ . insert_header ( PROMETHEUS_TEXT_FORMAT_HEADER )
66+ . body ( encoded_metrics) ,
67+ Err ( e) => HttpResponse :: InternalServerError ( ) . body ( e. to_string ( ) ) ,
6168 }
6269}
6370
You can’t perform that action at this time.
0 commit comments