From f2e5b281c9bc47b7a7701be35ab24ec0d5d4bd1a Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Sat, 22 Jun 2024 16:55:37 -0700 Subject: [PATCH] include method in otel.name for incoming requests Also change the name of the field from path to endpoint since it's not the exact request path, and swap the order of method and endpoint. --- src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2128f1e0..657a7a36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -145,19 +145,21 @@ async fn run_server() -> Result<(), error::Serve> { .layer(axum::middleware::from_fn(spawn_task)) .layer(TraceLayer::new_for_http().make_span_with( |request: &http::Request<_>| { - let path = if let Some(path) = + let endpoint = if let Some(endpoint) = request.extensions().get::() { - path.as_str() + endpoint.as_str() } else { request.uri().path() }; + let method = request.method(); + tracing::info_span!( "http_request", - otel.name = path, - %path, - method = %request.method(), + otel.name = format!("{method} {endpoint}"), + %method, + %endpoint, ) }, ))