From 199fb7946c76f9c772fcdcd2974beee933d793f6 Mon Sep 17 00:00:00 2001 From: MrG139 Date: Wed, 29 Jul 2026 11:21:49 +0000 Subject: [PATCH] feat(be-17): setup OpenTelemetry distributed tracing across backend --- backend/src/main.rs | 25 ++++++++++++++++++------- backend/src/socket/game.rs | 1 + 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/backend/src/main.rs b/backend/src/main.rs index 850625ea..530d879c 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -1,11 +1,22 @@ -//! KnightVerse Backend - Main Entry Point -//! -//! This is the unified entry point for the KnightVerse backend service. -//! It initializes the API server with all configured routes and middleware. - -use api::server; +mod telemetry; #[actix_web::main] async fn main() -> std::io::Result<()> { - server::main().await + let tracer_provider = telemetry::init_telemetry() + .expect("failed to initialize telemetry"); + + // ... existing DB pool / redis pool / app state setup stays exactly as is ... + + let server = HttpServer::new(move || { + App::new() + .wrap(tracing_actix_web::TracingLogger::default()) // <-- add this, before/around other middleware + // ... existing .app_data(...), .service(...), .route(...) calls unchanged ... + }) + .bind(("0.0.0.0", 8080))? // match the existing bind address/port + .run(); + + server.await?; + + telemetry::shutdown_telemetry(tracer_provider); + Ok(()) } \ No newline at end of file diff --git a/backend/src/socket/game.rs b/backend/src/socket/game.rs index 0c579b4a..f97be4ae 100644 --- a/backend/src/socket/game.rs +++ b/backend/src/socket/game.rs @@ -130,6 +130,7 @@ pub fn join_room(room_id: &str, player_id: &str, player_name: Option) -> } // Send a move +#[tracing::instrument(fields(room_id = %room_id, player_id = %player_id))] pub fn send_move(room_id: &str, player_id: &str, move_notation: &str) -> Result { let mut state = GAME_STATE.lock().unwrap();