refactor: improve tracing

This commit is contained in:
dusk 2023-05-05 14:24:33 +03:00
parent 0b0561406d
commit 66041f133c
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA

View File

@ -73,9 +73,7 @@ fn make_span_trace<B>(req: &Request<B>) -> Span {
let mut query_map = query let mut query_map = query
.and_then(|v| serde_qs::from_str::<HashMap<Cow<str>, Cow<str>>>(v).ok()) .and_then(|v| serde_qs::from_str::<HashMap<Cow<str>, Cow<str>>>(v).ok())
.unwrap_or_else(HashMap::new); .unwrap_or_else(HashMap::new);
if query_map.contains_key("token") { query_map.remove("token");
query_map.insert(Cow::Borrowed("token"), Cow::Borrowed("<redacted>"));
}
let request_id = req let request_id = req
.headers() .headers()
@ -86,19 +84,15 @@ fn make_span_trace<B>(req: &Request<B>) -> Span {
if query_map.is_empty() { if query_map.is_empty() {
tracing::debug_span!( tracing::debug_span!(
"request", "request",
method = %req.method(),
path = %req.uri().path(), path = %req.uri().path(),
version = ?req.version(),
id = %request_id, id = %request_id,
) )
} else { } else {
let query_display = QueryDisplay { map: query_map }; let query_display = QueryDisplay { map: query_map };
tracing::debug_span!( tracing::debug_span!(
"request", "request",
method = %req.method(),
path = %req.uri().path(), path = %req.uri().path(),
query = %query_display, query = %query_display,
version = ?req.version(),
id = %request_id, id = %request_id,
) )
} }
@ -109,8 +103,9 @@ pub(super) async fn handler(state: AppState) -> Result<(Router, Router), AppErro
.make_span_with(make_span_trace) .make_span_with(make_span_trace)
.on_request(|req: &Request<Body>, _span: &Span| { .on_request(|req: &Request<Body>, _span: &Span| {
tracing::debug!( tracing::debug!(
"started processing request with headers: {:?}", "started processing request {} on {:?}",
req.headers() req.method(),
req.version(),
) )
}); });