Skip to content

Commit

Permalink
state: interface: Trace DB operations
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Dec 13, 2024
1 parent 6309588 commit 28e8e85
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion state/src/interface/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use job_types::{
use libmdbx::{RO, RW};
use system_bus::SystemBus;
use system_clock::SystemClock;
use tracing::error;
use tracing::{error, info_span, Instrument};
use util::{err_str, raw_err_str};

use crate::{
Expand Down Expand Up @@ -304,10 +304,14 @@ impl StateInner {
let db = self.db.clone();
tokio::task::spawn_blocking(move || {
let tx = db.new_read_tx()?;
let _fn_span = tracing::info_span!("db_read_operation").entered();
let res = f(&tx)?;
drop(_fn_span); // End the operation span before committing

tx.commit()?;
Ok(res)
})
.instrument(info_span!("db_read_thread"))
.await
.map_err(err_str!(StateError::Runtime))?
}
Expand All @@ -325,10 +329,14 @@ impl StateInner {
let db = self.db.clone();
tokio::task::spawn_blocking(move || {
let tx = db.new_write_tx()?;
let _fn_span = tracing::info_span!("db_write_operation").entered();
let res = f(&tx)?;
drop(_fn_span); // End the operation span before committing

tx.commit()?;
Ok(res)
})
.instrument(info_span!("db_write_thread"))
.await
.map_err(err_str!(StateError::Runtime))?
}
Expand Down

0 comments on commit 28e8e85

Please sign in to comment.