Skip to content

Commit 886da92

Browse files
committed
tracing poc
1 parent 08c2236 commit 886da92

File tree

12 files changed

+568
-768
lines changed

12 files changed

+568
-768
lines changed

lightning-background-processor/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ lightning = { version = "0.2.0", path = "../lightning", default-features = false
2828
lightning-rapid-gossip-sync = { version = "0.2.0", path = "../lightning-rapid-gossip-sync", default-features = false }
2929
lightning-liquidity = { version = "0.2.0", path = "../lightning-liquidity", default-features = false }
3030
possiblyrandom = { version = "0.2", path = "../possiblyrandom", default-features = false }
31+
tracing = "0.1.41"
3132

3233
[dev-dependencies]
3334
tokio = { version = "1.35", features = [ "macros", "rt", "rt-multi-thread", "sync", "time" ] }

lightning-liquidity/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ chrono = { version = "0.4", default-features = false, features = ["serde", "allo
3333
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
3434
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
3535
backtrace = { version = "0.3", optional = true }
36+
tracing = "0.1.41"
3637

3738
[dev-dependencies]
3839
lightning = { version = "0.2.0", path = "../lightning", default-features = false, features = ["_test_utils"] }

lightning-macros/src/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use proc_macro::{Delimiter, Group, TokenStream, TokenTree};
2525
use proc_macro2::TokenStream as TokenStream2;
2626
use quote::quote;
2727
use syn::spanned::Spanned;
28-
use syn::{parse, ImplItemFn, Token};
28+
use syn::{parse, Attribute, FnArg, ImplItem, ImplItemFn, ItemImpl, Meta, Token, Visibility};
2929
use syn::{parse_macro_input, Item};
3030

3131
fn add_async_method(mut parsed: ImplItemFn) -> TokenStream {
@@ -400,3 +400,30 @@ pub fn xtest_inventory(_input: TokenStream) -> TokenStream {
400400

401401
TokenStream::from(expanded)
402402
}
403+
404+
/// Auto-enters the parent span.
405+
#[proc_macro_attribute]
406+
pub fn auto_span_methods(_attr: TokenStream, item: TokenStream) -> TokenStream {
407+
let mut input = parse_macro_input!(item as ItemImpl);
408+
409+
for item in input.items.iter_mut() {
410+
if let ImplItem::Fn(method) = item {
411+
if let Visibility::Public(_) = method.vis {
412+
// Skip the method that sets the node_span
413+
if method.sig.ident == "set_node_id" {
414+
continue;
415+
}
416+
417+
if let Some(FnArg::Receiver(_)) = method.sig.inputs.first() {
418+
let block = &method.block;
419+
method.block = syn::parse_quote!({
420+
let _entered_span = self.node_span.enter();
421+
#block
422+
});
423+
}
424+
}
425+
}
426+
}
427+
428+
TokenStream::from(quote!(#input))
429+
}

lightning-rapid-gossip-sync/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lightning = { version = "0.2.0", path = "../lightning", default-features = false
1919
bitcoin = { version = "0.32.2", default-features = false }
2020
bitcoin_hashes = { version = "0.14.0", default-features = false }
2121
bitcoin-io = { version = "0.1.2", default-features = false }
22+
tracing = "0.1.41"
2223

2324
[target.'cfg(ldk_bench)'.dependencies]
2425
criterion = { version = "0.4", optional = true, default-features = false }

lightning/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ backtrace = { version = "0.3", optional = true }
5050

5151
libm = { version = "0.2", default-features = false }
5252
inventory = { version = "0.3", optional = true }
53+
tracing = "0.1.41"
54+
tracing-subscriber = "0.3.20"
5355

5456
[dev-dependencies]
5557
regex = "1.5.6"

lightning/src/ln/channel.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,20 @@ where
10061006
}
10071007
}
10081008

1009+
pub fn span_from_context<S: Deref>(
1010+
context: &ChannelContext<S>, payment_hash: Option<PaymentHash>,
1011+
) -> tracing::Span
1012+
where
1013+
S::Target: SignerProvider,
1014+
{
1015+
tracing::info_span!(
1016+
"channel",
1017+
peer_id = %context.counterparty_node_id,
1018+
channel_id = %context.channel_id,
1019+
payment_hash = %payment_hash
1020+
)
1021+
}
1022+
10091023
macro_rules! secp_check {
10101024
($res: expr, $err: expr) => {
10111025
match $res {

0 commit comments

Comments
 (0)