Skip to content

Commit

Permalink
Instrumented macro refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusz-reichert authored and m-reichert committed Jan 30, 2025
1 parent 7fce6ba commit 8b7942e
Show file tree
Hide file tree
Showing 16 changed files with 149 additions and 146 deletions.
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
workspace = { members = ["instrumented_macro"] }
workspace = { members = ["electrs_macros"] }

[package]
name = "electrs"
version = "0.4.1"
Expand All @@ -17,17 +18,14 @@ default-run = "electrs"
liquid = ["elements"]
electrum-discovery = ["electrum-client"]
bench = []
default = ["no-otlp-tracing"]
otlp-tracing = [
"tracing/max_level_trace",
"tracing",
"tracing-subscriber",
"opentelemetry",
"tracing-opentelemetry",
"opentelemetry-otlp",
"opentelemetry-semantic-conventions"
]
no-otlp-tracing = [
"tracing/max_level_off"
"opentelemetry-semantic-conventions",
"electrs_macros/otlp-tracing"
]

[dependencies]
Expand Down Expand Up @@ -71,12 +69,12 @@ tracing-opentelemetry = { version = "0.21.0", optional = true }
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"], optional = true }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"], optional = true }
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
tracing = { version = "0.1.40", default-features = false, features = ["attributes"], optional = true }

# optional dependencies for electrum-discovery
electrum-client = { version = "0.8", optional = true }
zmq = "0.10.0"
instrumented_macro = { path = "instrumented_macro" }
electrs_macros = { path = "electrs_macros", default-features = false }

[dev-dependencies]
bitcoind = { version = "0.36", features = ["25_0"] }
Expand Down
5 changes: 4 additions & 1 deletion instrumented_macro/Cargo.toml → electrs_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
[package]
name = "instrumented_macro"
name = "electrs_macros"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[features]
otlp-tracing = []

[dependencies]
syn = "2.0"
quote = "1.0"
Expand Down
15 changes: 12 additions & 3 deletions instrumented_macro/src/lib.rs → electrs_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, ItemFn};


#[proc_macro_attribute]
pub fn instrumented(attr: TokenStream, item: TokenStream) -> TokenStream {
#[cfg(feature = "otlp-tracing")]
pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
use quote::quote;
use syn::{parse_macro_input, ItemFn};

let additional_fields = if !attr.is_empty() {
let attr_tokens: proc_macro2::TokenStream = attr.into();
quote! {, #attr_tokens }
Expand All @@ -23,4 +26,10 @@ pub fn instrumented(attr: TokenStream, item: TokenStream) -> TokenStream {
};

expanded.into()
}

#[proc_macro_attribute]
#[cfg(not(feature = "otlp-tracing"))]
pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
item
}
2 changes: 1 addition & 1 deletion src/bin/electrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn main_() {
}
}

#[cfg(feature = "no-otlp-tracing")]
#[cfg(not(feature = "otlp-tracing"))]
fn main() {
main_();
}
Expand Down
Loading

0 comments on commit 8b7942e

Please sign in to comment.