Skip to content

Commit 918e73d

Browse files
mario-reiphilippem
authored andcommitted
instrumented macro usage
1 parent de494f9 commit 918e73d

File tree

11 files changed

+107
-108
lines changed

11 files changed

+107
-108
lines changed

src/daemon.rs

+34-34
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use bitcoin::consensus::encode::{deserialize, serialize_hex};
2020
#[cfg(feature = "liquid")]
2121
use elements::encode::{deserialize, serialize_hex};
2222

23-
use tracing::instrument;
23+
use instrumented_macro::instrumented;
2424

2525
use crate::chain::{Block, BlockHash, BlockHeader, Network, Transaction, Txid};
2626
use crate::metrics::{HistogramOpts, HistogramVec, Metrics};
@@ -44,7 +44,7 @@ lazy_static! {
4444
const MAX_ATTEMPTS: u32 = 5;
4545
const RETRY_WAIT_DURATION: Duration = Duration::from_secs(1);
4646

47-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
47+
#[instrumented]
4848
fn parse_hash<T>(value: &Value) -> Result<T>
4949
where
5050
T: FromStr,
@@ -58,7 +58,7 @@ where
5858
.chain_err(|| format!("non-hex value: {}", value))?)
5959
}
6060

61-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
61+
#[instrumented]
6262
fn header_from_value(value: Value) -> Result<BlockHeader> {
6363
let header_hex = value
6464
.as_str()
@@ -153,7 +153,7 @@ struct Connection {
153153
signal: Waiter,
154154
}
155155

156-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
156+
#[instrumented]
157157
fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
158158
loop {
159159
match TcpStream::connect_timeout(&addr, *DAEMON_CONNECTION_TIMEOUT) {
@@ -176,7 +176,7 @@ fn tcp_connect(addr: SocketAddr, signal: &Waiter) -> Result<TcpStream> {
176176
}
177177

178178
impl Connection {
179-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
179+
#[instrumented]
180180
fn new(
181181
addr: SocketAddr,
182182
cookie_getter: Arc<dyn CookieGetter>,
@@ -196,12 +196,12 @@ impl Connection {
196196
})
197197
}
198198

199-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
199+
#[instrumented]
200200
fn reconnect(&self) -> Result<Connection> {
201201
Connection::new(self.addr, self.cookie_getter.clone(), self.signal.clone())
202202
}
203203

204-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
204+
#[instrumented]
205205
fn send(&mut self, request: &str) -> Result<()> {
206206
let cookie = &self.cookie_getter.get()?;
207207
let msg = format!(
@@ -215,7 +215,7 @@ impl Connection {
215215
})
216216
}
217217

218-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
218+
#[instrumented]
219219
fn recv(&mut self) -> Result<String> {
220220
// TODO: use proper HTTP parser.
221221
let mut in_header = true;
@@ -381,7 +381,7 @@ impl Daemon {
381381
Ok(daemon)
382382
}
383383

384-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
384+
#[instrumented]
385385
pub fn reconnect(&self) -> Result<Daemon> {
386386
Ok(Daemon {
387387
daemon_dir: self.daemon_dir.clone(),
@@ -396,7 +396,7 @@ impl Daemon {
396396
})
397397
}
398398

399-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
399+
#[instrumented]
400400
pub fn list_blk_files(&self) -> Result<Vec<PathBuf>> {
401401
let path = self.blocks_dir.join("blk*.dat");
402402
debug!("listing block files at {:?}", path);
@@ -432,7 +432,7 @@ impl Daemon {
432432
self.network.magic()
433433
}
434434

435-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
435+
#[instrumented]
436436
fn call_jsonrpc(&self, method: &str, request: &Value) -> Result<Value> {
437437
let mut conn = self.conn.lock().unwrap();
438438
let timer = self.latency.with_label_values(&[method]).start_timer();
@@ -450,7 +450,7 @@ impl Daemon {
450450
Ok(result)
451451
}
452452

453-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!(), method = %method))]
453+
#[instrumented(method = %method)]
454454
fn handle_request(&self, method: &str, params: &Value) -> Result<Value> {
455455
let id = self.message_id.next();
456456
let req = json!({"method": method, "params": params, "id": id});
@@ -473,12 +473,12 @@ impl Daemon {
473473
}
474474
}
475475

476-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
476+
#[instrumented]
477477
fn request(&self, method: &str, params: Value) -> Result<Value> {
478478
self.retry_request(method, &params)
479479
}
480480

481-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
481+
#[instrumented]
482482
fn retry_reconnect(&self) -> Daemon {
483483
// XXX add a max reconnection attempts limit?
484484
loop {
@@ -493,14 +493,14 @@ impl Daemon {
493493

494494
// Send requests in parallel over multiple RPC connections as individual JSON-RPC requests (with no JSON-RPC batching),
495495
// buffering the replies into a vector. If any of the requests fail, processing is terminated and an Err is returned.
496-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
496+
#[instrumented]
497497
fn requests(&self, method: &str, params_list: Vec<Value>) -> Result<Vec<Value>> {
498498
self.requests_iter(method, params_list).collect()
499499
}
500500

501501
// Send requests in parallel over multiple RPC connections, iterating over the results without buffering them.
502502
// Errors are included in the iterator and do not terminate other pending requests.
503-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
503+
#[instrumented]
504504
fn requests_iter<'a>(
505505
&'a self,
506506
method: &'a str,
@@ -523,29 +523,29 @@ impl Daemon {
523523

524524
// bitcoind JSONRPC API:
525525

526-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
526+
#[instrumented]
527527
pub fn getblockchaininfo(&self) -> Result<BlockchainInfo> {
528528
let info: Value = self.request("getblockchaininfo", json!([]))?;
529529
Ok(from_value(info).chain_err(|| "invalid blockchain info")?)
530530
}
531531

532-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
532+
#[instrumented]
533533
fn getnetworkinfo(&self) -> Result<NetworkInfo> {
534534
let info: Value = self.request("getnetworkinfo", json!([]))?;
535535
Ok(from_value(info).chain_err(|| "invalid network info")?)
536536
}
537537

538-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
538+
#[instrumented]
539539
pub fn getbestblockhash(&self) -> Result<BlockHash> {
540540
parse_hash(&self.request("getbestblockhash", json!([]))?)
541541
}
542542

543-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
543+
#[instrumented]
544544
pub fn getblockheader(&self, blockhash: &BlockHash) -> Result<BlockHeader> {
545545
header_from_value(self.request("getblockheader", json!([blockhash, /*verbose=*/ false]))?)
546546
}
547547

548-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
548+
#[instrumented]
549549
pub fn getblockheaders(&self, heights: &[usize]) -> Result<Vec<BlockHeader>> {
550550
let heights: Vec<Value> = heights.iter().map(|height| json!([height])).collect();
551551
let params_list: Vec<Value> = self
@@ -560,20 +560,20 @@ impl Daemon {
560560
Ok(result)
561561
}
562562

563-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
563+
#[instrumented]
564564
pub fn getblock(&self, blockhash: &BlockHash) -> Result<Block> {
565565
let block =
566566
block_from_value(self.request("getblock", json!([blockhash, /*verbose=*/ false]))?)?;
567567
assert_eq!(block.block_hash(), *blockhash);
568568
Ok(block)
569569
}
570570

571-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
571+
#[instrumented]
572572
pub fn getblock_raw(&self, blockhash: &BlockHash, verbose: u32) -> Result<Value> {
573573
self.request("getblock", json!([blockhash, verbose]))
574574
}
575575

576-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
576+
#[instrumented]
577577
pub fn getblocks(&self, blockhashes: &[BlockHash]) -> Result<Vec<Block>> {
578578
let params_list: Vec<Value> = blockhashes
579579
.iter()
@@ -610,7 +610,7 @@ impl Daemon {
610610

611611
/// Fetch the given transactions in parallel over multiple threads and RPC connections,
612612
/// ignoring any missing ones and returning whatever is available.
613-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
613+
#[instrumented]
614614
pub fn gettransactions_available(&self, txids: &[&Txid]) -> Result<Vec<(Txid, Transaction)>> {
615615
const RPC_INVALID_ADDRESS_OR_KEY: i64 = -5;
616616

@@ -635,7 +635,7 @@ impl Daemon {
635635
.collect()
636636
}
637637

638-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
638+
#[instrumented]
639639
pub fn gettransaction_raw(
640640
&self,
641641
txid: &Txid,
@@ -645,24 +645,24 @@ impl Daemon {
645645
self.request("getrawtransaction", json!([txid, verbose, blockhash]))
646646
}
647647

648-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
648+
#[instrumented]
649649
pub fn getmempooltx(&self, txhash: &Txid) -> Result<Transaction> {
650650
let value = self.request("getrawtransaction", json!([txhash, /*verbose=*/ false]))?;
651651
tx_from_value(value)
652652
}
653653

654-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
654+
#[instrumented]
655655
pub fn getmempooltxids(&self) -> Result<HashSet<Txid>> {
656656
let res = self.request("getrawmempool", json!([/*verbose=*/ false]))?;
657657
Ok(serde_json::from_value(res).chain_err(|| "invalid getrawmempool reply")?)
658658
}
659659

660-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
660+
#[instrumented]
661661
pub fn broadcast(&self, tx: &Transaction) -> Result<Txid> {
662662
self.broadcast_raw(&serialize_hex(tx))
663663
}
664664

665-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
665+
#[instrumented]
666666
pub fn broadcast_raw(&self, txhex: &str) -> Result<Txid> {
667667
let txid = self.request("sendrawtransaction", json!([txhex]))?;
668668
Ok(
@@ -674,7 +674,7 @@ impl Daemon {
674674
// Get estimated feerates for the provided confirmation targets using a batch RPC request
675675
// Missing estimates are logged but do not cause a failure, whatever is available is returned
676676
#[allow(clippy::float_cmp)]
677-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
677+
#[instrumented]
678678
pub fn estimatesmartfee_batch(&self, conf_targets: &[u16]) -> Result<HashMap<u16, f64>> {
679679
let params_list: Vec<Value> = conf_targets
680680
.iter()
@@ -709,7 +709,7 @@ impl Daemon {
709709
.collect())
710710
}
711711

712-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
712+
#[instrumented]
713713
fn get_all_headers(&self, tip: &BlockHash) -> Result<Vec<BlockHeader>> {
714714
let info: Value = self.request("getblockheader", json!([tip]))?;
715715
let tip_height = info
@@ -737,7 +737,7 @@ impl Daemon {
737737
}
738738

739739
// Returns a list of BlockHeaders in ascending height (i.e. the tip is last).
740-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
740+
#[instrumented]
741741
pub fn get_new_headers(
742742
&self,
743743
indexed_headers: &HeaderList,
@@ -770,7 +770,7 @@ impl Daemon {
770770
Ok(new_headers)
771771
}
772772

773-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
773+
#[instrumented]
774774
pub fn get_relayfee(&self) -> Result<f64> {
775775
let relayfee = self.getnetworkinfo()?.relayfee;
776776

src/electrum/server.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crypto::sha2::Sha256;
1313
use error_chain::ChainedError;
1414
use serde_json::{from_str, Value};
1515

16-
use tracing::instrument;
16+
use instrumented_macro::instrumented;
1717

1818
#[cfg(not(feature = "liquid"))]
1919
use bitcoin::consensus::encode::serialize_hex;
@@ -71,7 +71,7 @@ fn bool_from_value_or(val: Option<&Value>, name: &str, default: bool) -> Result<
7171
}
7272

7373
// TODO: implement caching and delta updates
74-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
74+
#[instrumented]
7575
fn get_status_hash(txs: Vec<(Txid, Option<BlockId>)>, query: &Query) -> Option<FullHash> {
7676
if txs.is_empty() {
7777
None
@@ -264,7 +264,7 @@ impl Connection {
264264
}))
265265
}
266266

267-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
267+
#[instrumented]
268268
fn blockchain_estimatefee(&self, params: &[Value]) -> Result<Value> {
269269
let conf_target = usize_from_value(params.get(0), "blocks_count")?;
270270
let fee_rate = self
@@ -392,7 +392,7 @@ impl Connection {
392392
Ok(json!(rawtx.to_lower_hex_string()))
393393
}
394394

395-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
395+
#[instrumented]
396396
fn blockchain_transaction_get_merkle(&self, params: &[Value]) -> Result<Value> {
397397
let txid = Txid::from(hash_from_value(params.get(0)).chain_err(|| "bad tx_hash")?);
398398
let height = usize_from_value(params.get(1), "height")?;
@@ -430,7 +430,7 @@ impl Connection {
430430
}))
431431
}
432432

433-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!(), method = %method))]
433+
#[instrumented(method = %method)]
434434
fn handle_command(&mut self, method: &str, params: &[Value], id: &Value) -> Result<Value> {
435435
let timer = self
436436
.stats
@@ -487,7 +487,7 @@ impl Connection {
487487
})
488488
}
489489

490-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
490+
#[instrumented]
491491
fn update_subscriptions(&mut self) -> Result<Vec<Value>> {
492492
let timer = self
493493
.stats
@@ -545,7 +545,7 @@ impl Connection {
545545
Ok(())
546546
}
547547

548-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
548+
#[instrumented]
549549
fn handle_replies(&mut self, receiver: Receiver<Message>) -> Result<()> {
550550
let empty_params = json!([]);
551551
loop {
@@ -610,7 +610,7 @@ impl Connection {
610610
}
611611
}
612612

613-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
613+
#[instrumented]
614614
fn parse_requests(mut reader: BufReader<TcpStream>, tx: &SyncSender<Message>) -> Result<()> {
615615
loop {
616616
let mut line = Vec::<u8>::new();
@@ -673,7 +673,7 @@ impl Connection {
673673
}
674674
}
675675

676-
#[instrument(skip_all, fields(module = module_path!(), file = file!(), line = line!()))]
676+
#[instrumented]
677677
fn get_history(
678678
query: &Query,
679679
scripthash: &[u8],

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern crate log;
1212
extern crate serde_derive;
1313
#[macro_use]
1414
extern crate serde_json;
15-
1615
#[macro_use]
1716
extern crate lazy_static;
1817

0 commit comments

Comments
 (0)