Skip to content

Commit fe5ca2d

Browse files
sandhosereivilibre
authored andcommitted
Make sure tracing spans are propagated in tokio::task::spawn
1 parent 40e67e4 commit fe5ca2d

File tree

1 file changed

+16
-13
lines changed
  • crates/syn2mas/src/mas_writer

1 file changed

+16
-13
lines changed

crates/syn2mas/src/mas_writer/mod.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use sqlx::{Executor, PgConnection, query, query_as};
2222
use thiserror::Error;
2323
use thiserror_ext::{Construct, ContextInto};
2424
use tokio::sync::mpsc::{self, Receiver, Sender};
25-
use tracing::{Level, error, info, warn};
25+
use tracing::{Instrument, Level, error, info, warn};
2626
use uuid::{NonNilUuid, Uuid};
2727

2828
use self::{
@@ -119,18 +119,21 @@ impl WriterConnectionPool {
119119
match self.connection_rx.recv().await {
120120
Some(Ok(mut connection)) => {
121121
let connection_tx = self.connection_tx.clone();
122-
tokio::task::spawn(async move {
123-
let to_return = match task(&mut connection).await {
124-
Ok(()) => Ok(connection),
125-
Err(error) => {
126-
error!("error in writer: {error}");
127-
Err(error)
128-
}
129-
};
130-
// This should always succeed in sending unless we're already shutting
131-
// down for some other reason.
132-
let _: Result<_, _> = connection_tx.send(to_return).await;
133-
});
122+
tokio::task::spawn(
123+
async move {
124+
let to_return = match task(&mut connection).await {
125+
Ok(()) => Ok(connection),
126+
Err(error) => {
127+
error!("error in writer: {error}");
128+
Err(error)
129+
}
130+
};
131+
// This should always succeed in sending unless we're already shutting
132+
// down for some other reason.
133+
let _: Result<_, _> = connection_tx.send(to_return).await;
134+
}
135+
.instrument(tracing::debug_span!("spawn_with_connection")),
136+
);
134137

135138
Ok(())
136139
}

0 commit comments

Comments
 (0)