From d9a35359bf8903f37f5f7aa77421ed35b626e0af Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 22 Feb 2022 15:21:06 +0100 Subject: Add metrics to web endpoint --- src/api/api_server.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/api') diff --git a/src/api/api_server.rs b/src/api/api_server.rs index 8502d9d8..a6bf5a44 100644 --- a/src/api/api_server.rs +++ b/src/api/api_server.rs @@ -16,7 +16,7 @@ use opentelemetry::{ use garage_util::data::*; use garage_util::error::Error as GarageError; -use garage_util::metrics::RecordDuration; +use garage_util::metrics::{gen_trace_id, RecordDuration}; use garage_model::garage::Garage; use garage_model::key_table::Key; @@ -110,16 +110,12 @@ async fn handler( debug!("{:?}", req); let tracer = opentelemetry::global::tracer("garage"); - let trace_id = gen_uuid(); let span = tracer .span_builder("S3 API call (unknown)") - .with_trace_id( - opentelemetry::trace::TraceId::from_hex(&hex::encode(&trace_id.as_slice()[..16])) - .unwrap(), - ) + .with_trace_id(gen_trace_id()) .with_attributes(vec![ KeyValue::new("method", format!("{}", req.method())), - KeyValue::new("uri", req.uri().path().to_string()), + KeyValue::new("uri", req.uri().to_string()), ]) .start(&tracer); @@ -177,9 +173,14 @@ async fn handler_stage2( let (endpoint, bucket_name) = Endpoint::from_request(&req, bucket_name.map(ToOwned::to_owned))?; debug!("Endpoint: {:?}", endpoint); - Context::current() - .span() - .update_name::(format!("S3 API {}", endpoint.name())); + let current_context = Context::current(); + let current_span = current_context.span(); + current_span.update_name::(format!("S3 API {}", endpoint.name())); + current_span.set_attribute(KeyValue::new("endpoint", endpoint.name())); + current_span.set_attribute(KeyValue::new( + "bucket", + bucket_name.clone().unwrap_or_default(), + )); let metrics_tags = &[KeyValue::new("api_endpoint", endpoint.name())]; -- cgit v1.2.3