Propogate span information to blocking operations

asonix/better-errors
Aode (lion) 2021-11-24 18:48:09 -06:00
parent 8aa0041b3d
commit 8b170096f1
3 changed files with 5 additions and 0 deletions

1
Cargo.lock generated
View File

@ -1779,6 +1779,7 @@ dependencies = [
"lemmy_utils",
"serde",
"serde_json",
"tracing",
"url",
]

View File

@ -23,4 +23,5 @@ diesel = "1.4.8"
actix-web = { version = "4.0.0-beta.9", default-features = false, features = ["cookies"] }
chrono = { version = "0.4.19", features = ["serde"] }
serde_json = { version = "1.0.68", features = ["preserve_order"] }
tracing = "0.1.29"
url = "2.2.2"

View File

@ -32,9 +32,12 @@ where
T: Send + 'static,
{
let pool = pool.clone();
let blocking_span = tracing::info_span!("blocking operation");
let res = actix_web::web::block(move || {
let entered = blocking_span.enter();
let conn = pool.get()?;
let res = (f)(&conn);
drop(entered);
Ok(res) as Result<T, LemmyError>
})
.await?;