From 14dcc8db15358df57ec2bc43aa112bfc9baa2326 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 17 Jun 2024 05:24:08 +0000 Subject: [PATCH] truncate MatchedPath for span field Signed-off-by: Jason Volk --- src/router/layers.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/router/layers.rs b/src/router/layers.rs index c419d653..4fe35164 100644 --- a/src/router/layers.rs +++ b/src/router/layers.rs @@ -182,7 +182,13 @@ fn tracing_span(request: &http::Request) -> tracing::Span { let path = request .extensions() .get::() - .map_or_else(|| request.uri().path(), |p| p.as_str()); + .map_or_else(|| request.uri().path(), truncated_matched_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)) +}