From 5844fcc89ec3fdad0e1e6342d8d4d2aa2ced5c84 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Fri, 23 Feb 2024 13:50:27 -0700 Subject: [PATCH] Log HTTP path in http logs (#8305) Co-Authored-By: Marshall Release Notes: - N/A Co-authored-by: Marshall --- crates/collab/src/main.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/collab/src/main.rs b/crates/collab/src/main.rs index 916deeb1f9bb937c6de25e140d1741b128fb2e5a..a29158337bebb17a8766a2de1a529a420b12bebb 100644 --- a/crates/collab/src/main.rs +++ b/crates/collab/src/main.rs @@ -1,10 +1,11 @@ use anyhow::anyhow; -use axum::{routing::get, Extension, Router}; +use axum::{extract::MatchedPath, routing::get, Extension, Router}; use collab::{ api::fetch_extensions_from_blob_store_periodically, db, env, executor::Executor, AppState, Config, MigrateConfig, Result, }; use db::Database; +use hyper::Request; use std::{ env::args, net::{SocketAddr, TcpListener}, @@ -84,6 +85,18 @@ async fn main() -> Result<()> { ) .layer( TraceLayer::new_for_http() + .make_span_with(|request: &Request<_>| { + let matched_path = request + .extensions() + .get::() + .map(MatchedPath::as_str); + + tracing::info_span!( + "http_request", + method = ?request.method(), + matched_path, + ) + }) .on_response(trace::DefaultOnResponse::new().level(Level::INFO)), );