vortex_metrics/
macros.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4/// A macro for optionally instrumenting a future, if tracing feature is enabled.
5#[macro_export]
6macro_rules! instrument {
7    ($span_name:expr, $expr:expr) => {
8        instrument!($span_name, [], $expr)
9    };
10    ($span_name:expr, [ $($key:ident = $value:expr),* $(,)? ], $expr:expr) => {
11        {
12            let task = $expr;
13            #[cfg(feature = "tracing")]
14            {
15                use tracing::Instrument;
16                task.instrument(tracing::info_span!(
17                    $span_name,
18                    $($key = $value,)*
19                ))
20            }
21            #[cfg(not(feature = "tracing"))]
22            {
23                task
24            }
25        }
26    };
27}