diff options
author | Alex Auvolat <alex@adnab.me> | 2022-02-22 15:21:06 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-03-14 10:53:50 +0100 |
commit | d9a35359bf8903f37f5f7aa77421ed35b626e0af (patch) | |
tree | 1b781e5e6de4d850e4938d6192f15c628e2eed27 /src/api/api_server.rs | |
parent | 2a5609b292de019085f93a79b7b73f7a8341bf51 (diff) | |
download | garage-d9a35359bf8903f37f5f7aa77421ed35b626e0af.tar.gz garage-d9a35359bf8903f37f5f7aa77421ed35b626e0af.zip |
Add metrics to web endpoint
Diffstat (limited to 'src/api/api_server.rs')
-rw-r--r-- | src/api/api_server.rs | 21 |
1 files changed, 11 insertions, 10 deletions
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::<String>(format!("S3 API {}", endpoint.name())); + let current_context = Context::current(); + let current_span = current_context.span(); + current_span.update_name::<String>(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())]; |