Skip to content

Commit e189db6

Browse files
mario-reiphilippem
authored andcommitted
Instrumented macro refactoring
1 parent 918e73d commit e189db6

16 files changed

+149
-146
lines changed

Cargo.lock

+19-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
workspace = { members = ["instrumented_macro"] }
1+
workspace = { members = ["electrs_macros"] }
2+
23
[package]
34
name = "electrs"
45
version = "0.4.1"
@@ -17,17 +18,14 @@ default-run = "electrs"
1718
liquid = ["elements"]
1819
electrum-discovery = ["electrum-client"]
1920
bench = []
20-
default = ["no-otlp-tracing"]
2121
otlp-tracing = [
22-
"tracing/max_level_trace",
22+
"tracing",
2323
"tracing-subscriber",
2424
"opentelemetry",
2525
"tracing-opentelemetry",
2626
"opentelemetry-otlp",
27-
"opentelemetry-semantic-conventions"
28-
]
29-
no-otlp-tracing = [
30-
"tracing/max_level_off"
27+
"opentelemetry-semantic-conventions",
28+
"electrs_macros/otlp-tracing"
3129
]
3230

3331
[dependencies]
@@ -71,12 +69,12 @@ tracing-opentelemetry = { version = "0.21.0", optional = true }
7169
opentelemetry-otlp = { version = "0.13.0", default-features = false, features = ["http-proto", "reqwest-client"], optional = true }
7270
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["env-filter", "fmt"], optional = true }
7371
opentelemetry-semantic-conventions = { version = "0.12.0", optional = true }
74-
tracing = { version = "0.1.40", default-features = false, features = ["attributes"] }
72+
tracing = { version = "0.1.40", default-features = false, features = ["attributes"], optional = true }
7573

7674
# optional dependencies for electrum-discovery
7775
electrum-client = { version = "0.8", optional = true }
7876
zmq = "0.10.0"
79-
instrumented_macro = { path = "instrumented_macro" }
77+
electrs_macros = { path = "electrs_macros", default-features = false }
8078

8179
[dev-dependencies]
8280
bitcoind = { version = "0.36", features = ["25_0"] }

instrumented_macro/Cargo.toml electrs_macros/Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
[package]
2-
name = "instrumented_macro"
2+
name = "electrs_macros"
33
version = "0.1.0"
44
edition = "2021"
55

66
[lib]
77
proc-macro = true
88

9+
[features]
10+
otlp-tracing = []
11+
912
[dependencies]
1013
syn = "2.0"
1114
quote = "1.0"

instrumented_macro/src/lib.rs electrs_macros/src/lib.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
use proc_macro::TokenStream;
2-
use quote::quote;
3-
use syn::{parse_macro_input, ItemFn};
2+
43

54
#[proc_macro_attribute]
6-
pub fn instrumented(attr: TokenStream, item: TokenStream) -> TokenStream {
5+
#[cfg(feature = "otlp-tracing")]
6+
pub fn trace(attr: TokenStream, item: TokenStream) -> TokenStream {
7+
use quote::quote;
8+
use syn::{parse_macro_input, ItemFn};
9+
710
let additional_fields = if !attr.is_empty() {
811
let attr_tokens: proc_macro2::TokenStream = attr.into();
912
quote! {, #attr_tokens }
@@ -23,4 +26,10 @@ pub fn instrumented(attr: TokenStream, item: TokenStream) -> TokenStream {
2326
};
2427

2528
expanded.into()
29+
}
30+
31+
#[proc_macro_attribute]
32+
#[cfg(not(feature = "otlp-tracing"))]
33+
pub fn trace(_attr: TokenStream, item: TokenStream) -> TokenStream {
34+
item
2635
}

src/bin/electrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ fn main_() {
159159
}
160160
}
161161

162-
#[cfg(feature = "no-otlp-tracing")]
162+
#[cfg(not(feature = "otlp-tracing"))]
163163
fn main() {
164164
main_();
165165
}

0 commit comments

Comments
 (0)