Sitelet https://github.com/init4tech/builder/commit/6dc5c9379148b789db283cdcaabfb8094e645d66
Skip to content

Commit 6dc5c93

Browse files
committed
refactor: use EnvTask's BlockConstruction span instead of ad-hoc instrument
Addresses Fraser's review on PR #269: - Drop the #[instrument] attribute from BundlePoller::task_future. Long-lived tasks shouldn't keep a single span open forever, and the Span::current() lookup inside record_block_number was flaky depending on the runtime log level. - Drop the record_block_number helper. Per-block context is already carried by the BlockConstruction span attached to each SimEnv (see EnvTask, env.rs:294), which already populates sim.ru.number, sim.host.number, sim.slot, etc. — the field names Fraser pointed to. - In the env-change branch of the select loop, capture env.clone_span() and use .instrument() on the inline async block that runs the refetch. This mirrors how SubmitTask::task_future picks up SimResult::clone_span() per work item, and how CacheTask::task_future enters env.span() for its sync work.
1 parent f45c986 commit 6dc5c93

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

‎src/tasks/cache/bundle.rs‎

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tokio::{
1010
task::JoinHandle,
1111
time,
1212
};
13-
use tracing::{Instrument, Span, debug, debug_span, instrument, trace, warn};
13+
use tracing::{Instrument, debug, debug_span, trace, warn};
1414

1515
type SseStream = Pin<Box<dyn Stream<Item = Result<CachedBundle, BuilderTxCacheError>> + Send>>;
1616

@@ -224,13 +224,7 @@ impl BundlePoller {
224224
ControlFlow::Continue(())
225225
}
226226

227-
#[instrument(
228-
skip_all,
229-
fields(url = %self.config.tx_pool_url, block_number = tracing::field::Empty),
230-
)]
231227
async fn task_future(mut self, outbound: mpsc::UnboundedSender<CachedBundle>) {
232-
self.record_block_number();
233-
234228
let (_, sub) = tokio::join!(self.fetch_and_forward(&outbound), self.subscribe());
235229
let mut backoff = INITIAL_RECONNECT_BACKOFF;
236230
let mut sse_stream = match sub {
@@ -261,20 +255,25 @@ impl BundlePoller {
261255
debug!("Block env channel closed, shutting down");
262256
break;
263257
}
264-
self.record_block_number();
265-
debug!("Block env changed, refetching all bundles");
266-
self.fetch_and_forward(&outbound).await;
258+
// Run the refetch under the BlockConstruction span built by
259+
// EnvTask, so its sim.ru.number / sim.host.number fields
260+
// attach to anything the refetch logs.
261+
let span = self
262+
.envs
263+
.borrow()
264+
.as_ref()
265+
.map_or_else(tracing::Span::none, |env| env.clone_span());
266+
async {
267+
debug!("Block env changed, refetching all bundles");
268+
self.fetch_and_forward(&outbound).await;
269+
}
270+
.instrument(span)
271+
.await;
267272
}
268273
}
269274
}
270275
}
271276

272-
fn record_block_number(&self) {
273-
if let Some(env) = self.envs.borrow().as_ref() {
274-
Span::current().record("block_number", env.rollup_block_number());
275-
}
276-
}
277-
278277
/// Spawns the task future and returns a receiver for bundles it finds.
279278
pub fn spawn(self) -> (mpsc::UnboundedReceiver<CachedBundle>, JoinHandle<()>) {
280279
let (outbound, inbound) = mpsc::unbounded_channel();

0 commit comments

Comments
 (0)