From e5627b2649a0e7881fd18c75560a995cd8f5247b Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 1 Dec 2025 13:45:39 +0900 Subject: [PATCH] server: add tracing span to user session --- src/server/session_handler.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/server/session_handler.rs b/src/server/session_handler.rs index c479929..c193543 100644 --- a/src/server/session_handler.rs +++ b/src/server/session_handler.rs @@ -4,6 +4,7 @@ use futures_util::{SinkExt, StreamExt}; use indoc::concatdoc; use sqlx::{MySqlConnection, MySqlPool}; use tokio::{net::UnixStream, sync::RwLock}; +use tracing::Instrument; use crate::{ core::{ @@ -77,13 +78,22 @@ pub async fn session_handler( } }; - tracing::info!("Accepted connection from user: {}", unix_user); + let span = tracing::info_span!("user_session", user = %unix_user); - let result = session_handler_with_unix_user(socket, &unix_user, db_pool).await; + (async move { + tracing::info!("Accepted connection from user: {}", unix_user); - tracing::info!("Finished handling requests for connection from user: {}", unix_user); + let result = session_handler_with_unix_user(socket, &unix_user, db_pool).await; - result + tracing::info!( + "Finished handling requests for connection from user: {}", + unix_user, + ); + + result + }) + .instrument(span) + .await } pub async fn session_handler_with_unix_user(