Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lsunsi committed Jul 22, 2024
1 parent 6ac532d commit 78f0d13
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bitcoincore_rpc::{
json::{AddressType, GetBalancesResult, ListTransactionResult},
RpcApi,
};
use opentelemetry::trace::FutureExt;
use opentelemetry::trace::{FutureExt, TraceContextExt};
use std::{future::Future, sync::Arc};

pub use bitcoincore_rpc as rpc;
Expand Down Expand Up @@ -76,15 +76,15 @@ impl Btc {
}

pub fn get_balances(&self) -> impl Future<Output = bitcoincore_rpc::Result<GetBalancesResult>> {
start_span(self.tracer.as_ref(), "getbalances");
let span = start_span(self.tracer.as_ref(), "getbalances");
let client = self.client.clone();

async move {
tokio::task::spawn_blocking(move || client.get_balances())
.await
.unwrap()
}
.with_current_context()
.with_context(opentelemetry::Context::current_with_span(span))
}

pub fn get_balance(
Expand Down Expand Up @@ -133,7 +133,10 @@ impl Btc {
}
}

fn start_span(tracer: &impl opentelemetry::trace::Tracer, method: &'static str) {
fn start_span(
tracer: &impl opentelemetry::trace::Tracer,
method: &'static str,
) -> impl opentelemetry::trace::Span {
opentelemetry::trace::SpanBuilder::from_name(method)
.with_kind(opentelemetry::trace::SpanKind::Client)
.with_attributes([
Expand All @@ -142,7 +145,7 @@ fn start_span(tracer: &impl opentelemetry::trace::Tracer, method: &'static str)
opentelemetry::KeyValue::new("rpc.system", "jsonrpc"),
opentelemetry::KeyValue::new("rpc.method", method),
])
.start(tracer);
.start(tracer)
}

#[cfg(test)]
Expand Down

0 comments on commit 78f0d13

Please sign in to comment.