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.
This commit is contained in:
Charles Hall 2024-06-22 16:55:37 -07:00
parent 1b51e0beec
commit f2e5b281c9
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF

View file

@ -145,19 +145,21 @@ async fn run_server() -> Result<(), error::Serve> {
.layer(axum::middleware::from_fn(spawn_task)) .layer(axum::middleware::from_fn(spawn_task))
.layer(TraceLayer::new_for_http().make_span_with( .layer(TraceLayer::new_for_http().make_span_with(
|request: &http::Request<_>| { |request: &http::Request<_>| {
let path = if let Some(path) = let endpoint = if let Some(endpoint) =
request.extensions().get::<MatchedPath>() request.extensions().get::<MatchedPath>()
{ {
path.as_str() endpoint.as_str()
} else { } else {
request.uri().path() request.uri().path()
}; };
let method = request.method();
tracing::info_span!( tracing::info_span!(
"http_request", "http_request",
otel.name = path, otel.name = format!("{method} {endpoint}"),
%path, %method,
method = %request.method(), %endpoint,
) )
}, },
)) ))