diff --git a/rust/otap-dataflow/crates/telemetry/src/internal_events.rs b/rust/otap-dataflow/crates/telemetry/src/internal_events.rs index 8dc472eace..2c94a6d214 100644 --- a/rust/otap-dataflow/crates/telemetry/src/internal_events.rs +++ b/rust/otap-dataflow/crates/telemetry/src/internal_events.rs @@ -35,8 +35,11 @@ pub mod _private { // See issue: https://github.com/tokio-rs/tracing/issues/2774 #[macro_export] macro_rules! otel_info { - ($name:expr $(, $($fields:tt)*)?) => { - $crate::_private::info!(name: $name, target: env!("CARGO_PKG_NAME"), { $($($fields)*)? }, ""); + ($name:expr, $($fields:tt)+) => { + $crate::_private::info!(name: $name, target: env!("CARGO_PKG_NAME"), $($fields)+); + }; + ($name:expr) => { + $crate::_private::info!(name: $name, target: env!("CARGO_PKG_NAME"), ""); }; } @@ -54,8 +57,11 @@ macro_rules! otel_info { /// ``` #[macro_export] macro_rules! otel_warn { - ($name:expr $(, $($fields:tt)*)?) => { - $crate::_private::warn!(name: $name, target: env!("CARGO_PKG_NAME"), { $($($fields)*)? }, ""); + ($name:expr, $($fields:tt)+) => { + $crate::_private::warn!(name: $name, target: env!("CARGO_PKG_NAME"), $($fields)+); + }; + ($name:expr) => { + $crate::_private::warn!(name: $name, target: env!("CARGO_PKG_NAME"), ""); }; } @@ -69,79 +75,15 @@ macro_rules! otel_warn { /// # Example: /// ```ignore /// use otap_df_telemetry::otel_debug; -/// otel_debug!("processing.batch", batch_size = 100, "Processing batch of items"); -/// otel_debug!("processing.done", count = 5); // no message, just fields -/// otel_debug!("processing.start"); // event name only +/// otel_debug!("processing.batch", batch_size = 100); /// ``` #[macro_export] macro_rules! otel_debug { - // Name only - ($name:expr) => { - $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), { }, ""); - }; - - // Name + bare literal message (no fields) - ($name:expr, $message:literal) => { - $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), { }, $message); - }; - - // With fields (and optional trailing message) - delegate to helper - ($name:expr, $($rest:tt)+) => { - $crate::__otel_debug_impl!(@munch [$name] [] $($rest)+) - }; -} - -/// Internal helper macro for otel_debug! to parse fields with optional trailing message. -#[doc(hidden)] -#[macro_export] -macro_rules! __otel_debug_impl { - // Terminal: trailing literal message only - (@munch [$name:expr] [$($fields:tt)*] $message:literal) => { - $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), { $($fields)* }, $message); - }; - - // Terminal: no more tokens (no trailing message) - (@munch [$name:expr] [$($fields:tt)*]) => { - $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), { $($fields)* }, ""); - }; - - // Munch: key = ?value, ... (debug format with comma, more tokens follow) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = ?$val:expr, $($rest:tt)+) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = ?$val,] $($rest)+) - }; - // Munch: key = ?value, (debug format with trailing comma, nothing follows) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = ?$val:expr,) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = ?$val,]) - }; - // Munch: key = ?value (debug format, last field, no comma) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = ?$val:expr) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = ?$val,]) - }; - - // Munch: key = %value, ... (display format with comma, more tokens follow) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = %$val:expr, $($rest:tt)+) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = %$val,] $($rest)+) - }; - // Munch: key = %value, (display format with trailing comma, nothing follows) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = %$val:expr,) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = %$val,]) - }; - // Munch: key = %value (display format, last field, no comma) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = %$val:expr) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = %$val,]) - }; - - // Munch: key = value, ... (regular with comma, more tokens follow) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = $val:expr, $($rest:tt)+) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = $val,] $($rest)+) - }; - // Munch: key = value, (regular with trailing comma, nothing follows) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = $val:expr,) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = $val,]) + ($name:expr, $($fields:tt)+) => { + $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), $($fields)+); }; - // Munch: key = value (regular, last field, no comma) - (@munch [$name:expr] [$($acc:tt)*] $key:ident = $val:expr) => { - $crate::__otel_debug_impl!(@munch [$name] [$($acc)* $key = $val,]) + ($name:expr) => { + $crate::_private::debug!(name: $name, target: env!("CARGO_PKG_NAME"), ""); }; } @@ -159,8 +101,11 @@ macro_rules! __otel_debug_impl { /// ``` #[macro_export] macro_rules! otel_error { - ($name:expr $(, $($fields:tt)*)?) => { - $crate::_private::error!(name: $name, target: env!("CARGO_PKG_NAME"), { $($($fields)*)? }, ""); + ($name:expr, $($fields:tt)+) => { + $crate::_private::error!(name: $name, target: env!("CARGO_PKG_NAME"), $($fields)+); + }; + ($name:expr) => { + $crate::_private::error!(name: $name, target: env!("CARGO_PKG_NAME"), ""); }; } @@ -222,28 +167,4 @@ mod tests { raw_error!("raw error message", error = ?err); raw_error!("simple error message"); } - - #[test] - fn test_otel_debug() { - otel_debug!("debug.event"); - } - - #[test] - fn test_otel_debug_with_attributes() { - otel_debug!("debug.event.with_attributes", value = 42); - } - - #[test] - fn test_otel_debug_with_message() { - otel_debug!("debug.event.with_message", "This is a debug message"); - } - - #[test] - fn test_otel_debug_with_message_and_attributes() { - otel_debug!( - "debug.event.with_message_and_attributes", - value = 42, - "This is a debug message" - ); - } }