Skip to content

Commit

Permalink
Add span to each call
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Aug 23, 2023
1 parent 6ba01aa commit 435dbf4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bitcoincore_rpc::{
RpcApi,
};
use std::{collections::HashMap, future::Future, sync::Arc};
use tracing::Instrument;

pub use bitcoincore_rpc as rpc;

Expand Down Expand Up @@ -35,6 +36,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("listtransactions"))
}

pub fn list_since_block(
Expand All @@ -54,6 +56,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("listsinceblock"))
}

pub fn get_balances(&self) -> impl Future<Output = bitcoincore_rpc::Result<GetBalancesResult>> {
Expand All @@ -64,6 +67,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("getbalances"))
}

pub fn get_balance(
Expand All @@ -77,6 +81,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("getbalance"))
}

pub fn get_transaction(
Expand All @@ -90,6 +95,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("gettransaction"))
}

pub fn send_to_address(
Expand Down Expand Up @@ -118,6 +124,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("sendtoaddress"))
}

pub fn send_many(
Expand All @@ -142,6 +149,7 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("sendmany"))
}

/// DANGEROUS: this call will block the thread. it is not safe unless you know what you're doing.
Expand All @@ -163,9 +171,25 @@ impl Btc {
.await
.unwrap()
}
.instrument(span!("getnewaddress"))
}
}

#[macro_export]
macro_rules! span {
($method:literal) => {
tracing::info_span!(
"btcore",
service.name = "btcore",
otel.name = $method,
otel.kind = "client",
rpc.system = "jsonrpc",
rpc.service = "bitcoind",
rpc.method = $method,
)
};
}

#[cfg(test)]
mod test {
use super::*;
Expand Down

0 comments on commit 435dbf4

Please sign in to comment.