Skip to content

Commit 19a15d7

Browse files
committed
refactor: span_debug et al
1 parent fc8f4d5 commit 19a15d7

File tree

6 files changed

+77
-179
lines changed

6 files changed

+77
-179
lines changed

src/macros.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,31 @@ macro_rules! span_scoped {
77
};
88
}
99

10+
/// Helper macro to log a debug event within a span that is not currently
11+
/// entered.
12+
macro_rules! span_debug {
13+
($span:expr, $($arg:tt)*) => {
14+
span_scoped!($span, debug!($($arg)*))
15+
};
16+
}
17+
18+
/// Helper macro to log an info event within a span that is not currently
19+
/// entered.
20+
macro_rules! span_info {
21+
($span:expr, $($arg:tt)*) => {
22+
span_scoped!($span, info!($($arg)*))
23+
};
24+
25+
}
26+
27+
/// Helper macro to log a warning event within a span that is not currently
28+
/// entered.
29+
macro_rules! span_error {
30+
($span:expr, $($arg:tt)*) => {
31+
span_scoped!($span, error!($($arg)*))
32+
};
33+
}
34+
1035
/// Helper macro to unwrap a result or continue the loop with a tracing event.
1136
macro_rules! res_unwrap_or_continue {
1237
($result:expr, $span:expr, $level:ident!($($arg:tt)*)) => {

src/tasks/block/sim.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl Simulator {
207207
let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return };
208208

209209
let span = sim_env.span();
210-
span_scoped!(span, info!("new block environment received"));
210+
span_info!(span, "new block environment received");
211211

212212
// Calculate the deadline for this block simulation.
213213
// NB: This must happen _after_ taking a reference to the sim cache,
@@ -219,7 +219,7 @@ impl Simulator {
219219
.handle_build(constants.clone(), sim_cache, finish_by, sim_env.block_env.clone())
220220
.instrument(span.clone())
221221
.await
222-
.inspect_err(|err| span_scoped!(span, error!(%err, "error during block build")))
222+
.inspect_err(|err| span_error!(span, %err, "error during block build"))
223223
else {
224224
continue;
225225
};

src/tasks/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl EnvTask {
9898
let mut headers = match self.ru_provider.subscribe_blocks().await {
9999
Ok(poller) => poller,
100100
Err(err) => {
101-
span_scoped!(span, error!(%err, "Failed to subscribe to blocks"));
101+
span_error!(span, %err, "Failed to subscribe to blocks");
102102
return;
103103
}
104104
}

src/tasks/submit/builder_helper.rs

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! spawn_provider_send {
3232
let p = $provider.clone();
3333
let t = $tx.clone();
3434
tokio::spawn(async move {
35-
p.send_tx_envelope(t).await.inspect_err(|e| {
35+
p.send_tx_envelope(t).in_current_span().await.inspect_err(|e| {
3636
warn!(%e, "error in transaction broadcast")
3737
})
3838
}.instrument($span.clone()))
@@ -44,17 +44,13 @@ macro_rules! spawn_provider_send {
4444
macro_rules! check_slot_still_valid {
4545
($self:expr, $initial_slot:expr, $span:expr) => {
4646
if !$self.slot_still_valid($initial_slot) {
47-
$span.in_scope(|| {
48-
debug!(
49-
current_slot = $self
50-
.config
51-
.slot_calculator
52-
.current_slot()
53-
.expect("host chain has started"),
54-
initial_slot = $initial_slot,
55-
"slot changed before submission - skipping block"
56-
)
57-
});
47+
span_debug!(
48+
$span,
49+
current_slot =
50+
$self.config.slot_calculator.current_slot().expect("host chain has started"),
51+
initial_slot = $initial_slot,
52+
"slot changed before submission - skipping block"
53+
);
5854
counter!("builder.slot_missed").increment(1);
5955
return Ok(ControlFlow::Skip);
6056
}
@@ -115,7 +111,7 @@ impl BuilderHelperTask {
115111
// Set up a span for the send operation. We'll add this to the spawned
116112
// tasks
117113
let span = debug_span!("BuilderHelperTask::send_transaction", tx_hash = %tx.hash());
118-
span_scoped!(span, debug!("sending transaction to network"));
114+
span_debug!(span, "sending transaction to network");
119115

120116
// send the tx via the primary host_provider
121117
let fut = spawn_provider_send!(self.provider(), &tx, &span);
@@ -127,30 +123,29 @@ impl BuilderHelperTask {
127123

128124
// send the in-progress transaction over the outbound_tx_channel
129125
if self.outbound_tx_channel.send(*tx.tx_hash()).is_err() {
130-
span_scoped!(span, error!("receipts task gone"));
126+
span_error!(span, "receipts task gone");
131127
}
132128

133129
if let Err(error) = fut.await? {
134130
// Detect and handle transaction underprice errors
135131
if matches!(error, TransportError::ErrorResp(ref err) if err.code == -32603) {
136-
span_scoped!(
132+
span_debug!(
137133
span,
138-
debug!(%error, "underpriced transaction error - retrying tx with gas bump")
134+
%error,
135+
"underpriced transaction error - retrying tx with gas bump"
139136
);
140137
return Ok(ControlFlow::Retry);
141138
}
142139

143140
// Unknown error, log and skip
144-
span_scoped!(span, error!(%error, "Primary tx broadcast failed"));
141+
span_error!(span, %error, "Primary tx broadcast failed");
145142
return Ok(ControlFlow::Skip);
146143
}
147144

148-
span_scoped!(
145+
span_info!(
149146
span,
150-
info!(
151147
tx_hash = %tx.tx_hash(),
152148
"dispatched to network"
153-
)
154149
);
155150

156151
Ok(ControlFlow::Done)
@@ -190,9 +185,7 @@ impl BuilderHelperTask {
190185
.send_transaction(req)
191186
.instrument(span.clone())
192187
.await
193-
.inspect_err(|error| {
194-
span_scoped!(span, error!(%error, "error sending transaction"))
195-
})
188+
.inspect_err(|error| span_error!(span, %error, "error sending transaction"))
196189
.unwrap_or(ControlFlow::Retry);
197190

198191
let guard = span.entered();
@@ -261,11 +254,11 @@ impl BuilderHelperTask {
261254

262255
let span = sim_result.sim_env.span.clone();
263256

264-
span_scoped!(span, debug!("submit channel received block"));
257+
span_debug!(span, "submit channel received block");
265258

266259
// Don't submit empty blocks
267260
if sim_result.block.is_empty() {
268-
span_scoped!(span, debug!("received empty block - skipping"));
261+
span_debug!(span, "received empty block - skipping");
269262
continue;
270263
}
271264

0 commit comments

Comments
 (0)