Skip to content

Commit df52e75

Browse files
committed
refactor: avoid creating spans for skipped sim rounds
1 parent f00c06a commit df52e75

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

crates/sim/src/task.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ where
143143
let mut i = 1;
144144
// Run until the deadline is reached.
145145
loop {
146-
let span = info_span!("build", round = i);
147146
let finish_by = self.finish_by.into();
148147

149148
let next_round_time = Instant::now() + Duration::from_millis(SIM_SLEEP_MS);
@@ -163,19 +162,25 @@ where
163162
continue;
164163
}
165164

165+
let span = info_span!("build", round = i);
166+
166167
// If there are items to simulate, we run a simulation round.
167-
let fut = self.round().instrument(span);
168+
let fut = self.round().instrument(span.clone());
168169

169170
select! {
170171
biased;
171172
_ = tokio::time::sleep_until(finish_by) => {
173+
// This event is not a round event. It's a control flow
174+
// event for the outer loop. As such it's not in span
172175
debug!("Deadline reached, stopping sim loop");
173176
break;
174177
},
175178
_ = fut => {
176-
i+= 1;
177-
let remaining = self.env.sim_items().len();
178-
trace!(%remaining, round = i, "Round completed");
179+
i += 1;
180+
let remaining_items = self.env.sim_items().len();
181+
span.in_scope(|| {
182+
trace!(remaining_items, "Round completed");
183+
});
179184
}
180185
}
181186
}

0 commit comments

Comments
 (0)