Skip to content

Commit

Permalink
Added tracing support
Browse files Browse the repository at this point in the history
  • Loading branch information
myOmikron committed Apr 2, 2024
1 parent 2133997 commit 2fdf1f2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -110,6 +112,7 @@ where
<S as Model>::Primary: Field<Type = String>,
<S as Patch>::Decoder: Send + Sync + 'static,
{
#[instrument(level = "trace")]
async fn delete_expired(&self) -> Result<()> {
let db = &self.db;

Expand All @@ -129,7 +132,9 @@ where
<S as Model>::Primary: Field<Type = String>,
<S as Patch>::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()
Expand Down Expand Up @@ -164,6 +169,7 @@ where
Ok(())
}

#[instrument(level = "trace")]
async fn save(&self, session_record: &Record) -> Result<()> {
let Record {
id,
Expand Down Expand Up @@ -207,7 +213,9 @@ where
Ok(())
}

#[instrument(level = "trace")]
async fn load(&self, session_id: &Id) -> Result<Option<Record>> {
debug!("Loading session");
let db = &self.db;

let session = query!(db, S)
Expand All @@ -233,6 +241,7 @@ where
})
}

#[instrument(level = "trace")]
async fn delete(&self, session_id: &Id) -> Result<()> {
let db = &self.db;

Expand Down

0 comments on commit 2fdf1f2

Please sign in to comment.