Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

feat: spans with information #66

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl AuthBearer {
Self(contents.to_string())
}

fn decode_request_parts(req: &mut Parts) -> Result<Self, Rejection> {
fn decode_request_parts(req: &Parts) -> Result<Self, Rejection> {
// Get authorization header
let authorization = req
.headers
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/handlers/register.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ async fn overwrite_registration(
tags: HashSet<Arc<str>>,
relay_url: Arc<str>,
) -> error::Result<Response> {
info!(
"DBG:{}:overwrite_registration: upsert registration",
client_id
);
state
.registration_store
.upsert_registration(
Expand All @@ -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 {
Expand All @@ -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 <append_tags> and <remove_tags>...",
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()
Expand All @@ -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
}
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use {
Router,
},
config::Configuration,
http::Request,
hyper::Body,
opentelemetry::{sdk::Resource, KeyValue},
state::AppState,
std::{net::SocketAddr, sync::Arc},
Expand All @@ -17,7 +19,7 @@ use {
tower::ServiceBuilder,
tower_http::{
cors::{Any, CorsLayer},
trace::{DefaultMakeSpan, DefaultOnRequest, DefaultOnResponse, TraceLayer},
trace::{DefaultOnRequest, DefaultOnResponse, TraceLayer},
},
};

Expand Down Expand Up @@ -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<Body>| {
tracing::info_span!("http-request", "method" = ?request.method(), "uri" = ?request.uri())
})
.on_request(DefaultOnRequest::new().level(config.log_level()))
.on_response(
DefaultOnResponse::new()
Expand Down
1 change: 0 additions & 1 deletion tests/context/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
Expand Down
Loading