Skip to content

Commit a1ef7ef

Browse files
committed
Add tracing and spans
1 parent 5224c64 commit a1ef7ef

File tree

6 files changed

+146
-30
lines changed

6 files changed

+146
-30
lines changed

Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ log = { version = "0.4.27" }
3838
num = "0.4.3"
3939
rand = "0.8.0"
4040
tokio = { version = "1.43.0", features = ["full"] }
41+
tracing = "0.1.41"
4142

4243
mantis-sdk = { path = "mantis-sdk" }

mantis-sdk/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ alloy = { workspace = true }
2727
anyhow = { workspace = true }
2828
base64 = { workspace = true }
2929
chrono = { workspace = true }
30-
env_logger = { workspace = true }
31-
log = { workspace = true }
3230
num = { workspace = true }
3331
rand = { workspace = true }
3432
tokio = { workspace = true }
33+
tracing = { workspace = true }
3534

3635
[lints.clippy]
3736
obfuscated_if_else = "allow"

mantis-sdk/src/ethereum.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use alloy::sol;
66
use alloy::transports::Transport;
77
use anyhow::{anyhow, Result};
88
use chrono::Utc;
9-
use log::info;
9+
use tracing::{info, instrument, span, Level};
1010
use Escrow::NewIntent;
1111

1212
use crate::{random_intent_id, retry};
@@ -34,6 +34,7 @@ pub struct GasFees {
3434
pub max_priority_fee_per_gas: u128,
3535
}
3636

37+
#[instrument(skip_all)]
3738
pub async fn escrow_funds<P, T>(
3839
provider: P,
3940
escrow_address: Address,
@@ -90,6 +91,7 @@ where
9091
.await
9192
},
9293
3,
94+
Some(span!(Level::INFO, "escrowFunds")),
9395
)
9496
.await?;
9597

@@ -108,12 +110,14 @@ where
108110
.ok_or(anyhow!("No transaction receipt"))
109111
},
110112
5,
113+
Some(span!(Level::INFO, "get_transaction_receipt")),
111114
)
112115
.await?;
113116

114117
Ok(receipt)
115118
}
116119

120+
#[instrument(skip_all)]
117121
pub async fn solve_intent_remote<P, T>(
118122
provider: P,
119123
escrow_address: Address,
@@ -139,6 +143,7 @@ where
139143
.await
140144
},
141145
3,
146+
Some(span!(Level::INFO, "solveIntentRemote")),
142147
)
143148
.await?;
144149

@@ -157,12 +162,14 @@ where
157162
.ok_or(anyhow!("No transaction receipt"))
158163
},
159164
5,
165+
Some(span!(Level::INFO, "get_transaction_receipt")),
160166
)
161167
.await?;
162168

163169
Ok(receipt)
164170
}
165171

172+
#[instrument(skip_all)]
166173
pub async fn solve_intent_local<P, T>(
167174
provider: P,
168175
escrow_address: Address,
@@ -184,6 +191,7 @@ where
184191
.await
185192
},
186193
3,
194+
Some(span!(Level::INFO, "solveIntentLocal")),
187195
)
188196
.await?;
189197

@@ -202,12 +210,14 @@ where
202210
.ok_or(anyhow!("No transaction receipt"))
203211
},
204212
5,
213+
Some(span!(Level::INFO, "get_transaction_receipt")),
205214
)
206215
.await?;
207216

208217
Ok(receipt)
209218
}
210219

220+
#[instrument(skip_all)]
211221
pub async fn cancel_intent<P, T>(
212222
provider: P,
213223
escrow_address: Address,
@@ -219,7 +229,12 @@ where
219229
{
220230
let contract = Escrow::new(escrow_address, provider.clone());
221231

222-
let pending = retry(|| async { contract.cancelIntent(intent_id).send().await }, 3).await?;
232+
let pending = retry(
233+
|| async { contract.cancelIntent(intent_id).send().await },
234+
3,
235+
Some(span!(Level::INFO, "cancelIntent")),
236+
)
237+
.await?;
223238

224239
let tx_hash = pending.tx_hash();
225240

@@ -236,13 +251,15 @@ where
236251
.ok_or(anyhow!("No transaction receipt"))
237252
},
238253
5,
254+
Some(span!(Level::INFO, "get_transaction_receipt")),
239255
)
240256
.await?;
241257

242258
info!("Canceled intent {} on Ethereum", intent_id);
243259
Ok(receipt)
244260
}
245261

262+
#[instrument(skip_all)]
246263
pub async fn approve_erc20<P, T>(
247264
provider: P,
248265
token: Address,
@@ -258,6 +275,7 @@ where
258275
let pending = retry(
259276
|| async { token_contract.approve(spender, amount).send().await },
260277
3,
278+
Some(span!(Level::INFO, "approve")),
261279
)
262280
.await?;
263281

@@ -273,12 +291,14 @@ where
273291
.ok_or(anyhow!("No transaction receipt"))
274292
},
275293
5,
294+
Some(span!(Level::INFO, "get_transaction_receipt")),
276295
)
277296
.await?;
278297

279298
Ok(receipt)
280299
}
281300

301+
#[instrument(skip_all)]
282302
pub async fn send_raw_tx<P, T>(
283303
provider: P,
284304
to: Address,
@@ -308,7 +328,12 @@ where
308328
..Default::default()
309329
};
310330

311-
let pending = retry(|| provider.send_transaction(transaction.clone()), 3).await?;
331+
let pending = retry(
332+
|| provider.send_transaction(transaction.clone()),
333+
3,
334+
Some(span!(Level::INFO, "send_transaction")),
335+
)
336+
.await?;
312337
let tx_hash = pending.tx_hash();
313338

314339
info!("Ethereum transaction {} was sent to the network", tx_hash);
@@ -321,6 +346,7 @@ where
321346
.ok_or(anyhow!("No transaction receipt"))
322347
},
323348
5,
349+
Some(span!(Level::INFO, "get_transaction_receipt")),
324350
)
325351
.await?;
326352

mantis-sdk/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ use std::fmt::Display;
22
use std::future::Future;
33
use std::time::Duration;
44

5-
use log::{error, warn};
65
use rand::Rng;
76
use tokio::time::sleep;
7+
use tracing::{error, warn, Span};
88

99
pub mod auction;
1010
pub mod ethereum;
1111
pub mod solana;
1212

13-
pub async fn retry<F, Fut, T, E>(mut function: F, max_tries: u32) -> Result<T, E>
13+
pub async fn retry<F, Fut, T, E>(mut function: F, max_tries: u32, span: Option<Span>) -> Result<T, E>
1414
where
1515
F: FnMut() -> Fut,
1616
Fut: Future<Output = Result<T, E>>,
1717
E: Display,
1818
{
19+
let _enter = span.as_ref().map(|s| s.enter());
1920
let mut count = 0;
2021
loop {
2122
count += 1;

0 commit comments

Comments
 (0)