From 0033f344bda7bf05d0fcd0c05bb3d94c325b9ddc Mon Sep 17 00:00:00 2001 From: Derek Date: Thu, 31 Aug 2023 22:04:28 +0100 Subject: [PATCH 1/2] feat: spans with information --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index fe5c147..f5680e0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,8 @@ use { Router, }, config::Configuration, + http::Request, + hyper::Body, opentelemetry::{sdk::Resource, KeyValue}, state::AppState, std::{net::SocketAddr, sync::Arc}, @@ -17,7 +19,7 @@ use { tower::ServiceBuilder, tower_http::{ cors::{Any, CorsLayer}, - trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer}, + trace::{DefaultOnRequest, DefaultOnResponse, TraceLayer}, }, }; @@ -96,7 +98,9 @@ pub async fn bootstrap( let global_middleware = ServiceBuilder::new().layer( TraceLayer::new_for_http() - .make_span_with(DefaultMakeSpan::new().include_headers(true)) + .make_span_with(|request: &Request| { + tracing::info_span!("http-request", "method" = ?request.method(), "uri" = ?request.uri()) + }) .on_request(DefaultOnRequest::new().level(config.log_level())) .on_response( DefaultOnResponse::new() From af877051edb016e2a242b88d882a6e029df87502 Mon Sep 17 00:00:00 2001 From: Xavier Basty Date: Thu, 7 Sep 2023 15:01:18 +0200 Subject: [PATCH 2/2] feat: debug traces in register --- src/auth/mod.rs | 4 ++-- src/handlers/register.rs | 21 +++++++++++++++++++++ tests/context/server.rs | 1 - 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/auth/mod.rs b/src/auth/mod.rs index c90f7f8..4ae3029 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -60,7 +60,7 @@ impl AuthBearer { Self(contents.to_string()) } - fn decode_request_parts(req: &mut Parts) -> Result { + fn decode_request_parts(req: &Parts) -> Result { // Get authorization header let authorization = req .headers @@ -73,7 +73,7 @@ impl AuthBearer { let split = authorization.split_once(' '); match split { // Found proper bearer - Some((name, contents)) if name == "Bearer" => Ok(Self::from_header(contents)), + Some(("Bearer", contents)) => Ok(Self::from_header(contents)), // Found empty bearer _ if authorization == "Bearer" => Ok(Self::from_header("")), // Found nothing diff --git a/src/handlers/register.rs b/src/handlers/register.rs index 6a6f719..ffe55b5 100644 --- a/src/handlers/register.rs +++ b/src/handlers/register.rs @@ -70,6 +70,10 @@ async fn overwrite_registration( tags: HashSet>, relay_url: Arc, ) -> error::Result { + info!( + "DBG:{}:overwrite_registration: upsert registration", + client_id + ); state .registration_store .upsert_registration( @@ -79,6 +83,10 @@ async fn overwrite_registration( ) .await?; + info!( + "DBG:{}:overwrite_registration: cache registration", + client_id + ); state .registration_cache .insert(client_id.into_value(), CachedRegistration { @@ -100,15 +108,27 @@ async fn update_registration( let append_tags = append_tags.unwrap_or_default(); let remove_tags = remove_tags.unwrap_or_default(); + info!( + "DBG:{}:update_registration: process intersection of and ...", + client_id + ); if remove_tags.intersection(&append_tags).count() > 0 { return Err(Error::InvalidUpdateRequest); } + info!( + "DBG:{}:update_registration: get current registration", + client_id + ); let registration = state .registration_store .get_registration(client_id.as_ref()) .await?; + info!( + "DBG:{}:update_registration: get current registration", + client_id + ); let tags = registration .tags .into_iter() @@ -120,5 +140,6 @@ async fn update_registration( .cloned() .collect(); + info!("DBG:{}: overwrite registration", client_id); overwrite_registration(state, client_id, tags, relay_url).await } diff --git a/tests/context/server.rs b/tests/context/server.rs index f7471e9..768b972 100644 --- a/tests/context/server.rs +++ b/tests/context/server.rs @@ -42,7 +42,6 @@ impl Gilgamesh { std::thread::spawn(move || { rt.block_on(async move { - let public_port = public_port; let mongo_address = env::var("MONGO_ADDRESS").unwrap_or( "mongodb://admin:admin@mongo:27017/gilgamesh?authSource=admin".into(), );