Closed brayniac closed 4 months ago
@thinkingfish pointed me to this PR. Here's a suggestion that lets you cut down on needing to have #[cfg(feature = "metrics")]
everywhere. You can define a metric!
macro that conditionally expands to either nothing or its input:
#[cfg(feature = "metrics")]
macro_rules! metrics {
{ $( $tt:tt )* } => { $( $tt )* }
}
#[cfg(not(feature = "metrics"))]
macro_rules! metrics {
{ $( $tt:tt)* } => {}
}
Then, later on, instead of using #[cfg(feature = "metrics")]
you wrap the metrics-related code in a metrics!
macro
metrics! {
METRIC.increment();
}
You still have to modify all the calls but you don't have to repeat #[cfg]
everywhere so it is easier to change in the future if you need to.
@thinkingfish pointed me to this PR. Here's a suggestion that lets you cut down on needing to have
#[cfg(feature = "metrics")]
everywhere. You can define ametric!
macro that conditionally expands to either nothing or its input:#[cfg(feature = "metrics")] macro_rules! metrics { { $( $tt:tt )* } => { $( $tt )* } } #[cfg(not(feature = "metrics"))] macro_rules! metrics { { $( $tt:tt)* } => {} }
Then, later on, instead of using
#[cfg(feature = "metrics")]
you wrap the metrics-related code in ametrics!
macrometrics! { METRIC.increment(); }
You still have to modify all the calls but you don't have to repeat
#[cfg]
everywhere so it is easier to change in the future if you need to.
Not a bad idea!
Changes the way metrics are included in pelikan-net, moving them behind a feature flag to make them opt-in.