truncate MatchedPath for span field

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-17 05:24:08 +00:00
parent 213a6d441f
commit 14dcc8db15

View file

@ -182,7 +182,13 @@ fn tracing_span<T>(request: &http::Request<T>) -> tracing::Span {
let path = request let path = request
.extensions() .extensions()
.get::<MatchedPath>() .get::<MatchedPath>()
.map_or_else(|| request.uri().path(), |p| p.as_str()); .map_or_else(|| request.uri().path(), truncated_matched_path);
tracing::info_span!("router:", %path) tracing::info_span!("router:", %path)
} }
fn truncated_matched_path(path: &MatchedPath) -> &str {
path.as_str()
.rsplit_once(':')
.map_or(path.as_str(), |path| path.0.strip_suffix('/').unwrap_or(path.0))
}