From 2fdf1f2ed5ded403659909bc7bb85349fcb56b8d Mon Sep 17 00:00:00 2001 From: myOmikron Date: Tue, 2 Apr 2024 14:15:41 +0200 Subject: [PATCH] Added tracing support --- Cargo.lock | 1 + Cargo.toml | 3 +++ src/lib.rs | 9 +++++++++ 3 files changed, 13 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7e545af..f2cc09c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2261,6 +2261,7 @@ dependencies = [ "serde_json", "thiserror", "tower-sessions", + "tracing", "uuid", ] diff --git a/Cargo.toml b/Cargo.toml index 3629908..0329972 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,9 @@ async-trait = "~0.1" # required for SessionStore trait serde_json = { version = "~1" } +# Tracing +tracing = { version = "~0.1" } + # Error management thiserror = { version = "~1" } base64 = { version = "~0.22" } diff --git a/src/lib.rs b/src/lib.rs index 9dfd3f3..ba85a90 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,6 +37,8 @@ use tower_sessions::session_store::Error; use tower_sessions::session_store::Result; use tower_sessions::ExpiredDeletion; use tower_sessions::SessionStore; +use tracing::debug; +use tracing::instrument; /// Implement this trait on a [Model] that should be used /// to store sessions in a database. @@ -110,6 +112,7 @@ where ::Primary: Field, ::Decoder: Send + Sync + 'static, { + #[instrument(level = "trace")] async fn delete_expired(&self) -> Result<()> { let db = &self.db; @@ -129,7 +132,9 @@ where ::Primary: Field, ::Decoder: Send + Sync + 'static, { + #[instrument(level = "trace")] async fn create(&self, session_record: &mut Record) -> Result<()> { + debug!("Creating new session"); let mut tx = self .db .start_transaction() @@ -164,6 +169,7 @@ where Ok(()) } + #[instrument(level = "trace")] async fn save(&self, session_record: &Record) -> Result<()> { let Record { id, @@ -207,7 +213,9 @@ where Ok(()) } + #[instrument(level = "trace")] async fn load(&self, session_id: &Id) -> Result> { + debug!("Loading session"); let db = &self.db; let session = query!(db, S) @@ -233,6 +241,7 @@ where }) } + #[instrument(level = "trace")] async fn delete(&self, session_id: &Id) -> Result<()> { let db = &self.db;