log method on tracing req spans, fix path sometimes being truncated

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-10-25 21:08:34 -04:00
parent 652b04b9b6
commit 2ce91f33af
2 changed files with 14 additions and 8 deletions

View file

@ -184,12 +184,20 @@ fn catch_panic(err: Box<dyn Any + Send + 'static>) -> http::Response<http_body_u
}
fn tracing_span<T>(request: &http::Request<T>) -> tracing::Span {
let path = request
.extensions()
.get::<MatchedPath>()
.map_or_else(|| request.uri().path(), truncated_matched_path);
let path = request.extensions().get::<MatchedPath>().map_or_else(
|| {
request
.uri()
.path_and_query()
.expect("all requests have a path")
.as_str()
},
truncated_matched_path,
);
tracing::info_span!("router:", %path)
let method = request.method();
tracing::info_span!("router:", %method, %path)
}
fn truncated_matched_path(path: &MatchedPath) -> &str {