mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
build(deps): bump opentelemetry crates to 0.27 (#6774)
This commit is contained in:
@ -1,16 +1,5 @@
|
||||
//! Utilities to easily create opentelemetry contexts, meters and metrics.
|
||||
|
||||
/// Create a metrics [`Context`][Context] with the specified name.
|
||||
///
|
||||
/// [Context]: opentelemetry::Context
|
||||
#[macro_export]
|
||||
macro_rules! metrics_context {
|
||||
($name:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<$crate::opentelemetry::Context> =
|
||||
once_cell::sync::Lazy::new($crate::opentelemetry::Context::current);
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a global [`Meter`][Meter] with the specified name and an optional description.
|
||||
///
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
@ -20,14 +9,14 @@ macro_rules! global_meter {
|
||||
static $name: once_cell::sync::Lazy<$crate::opentelemetry::metrics::Meter> =
|
||||
once_cell::sync::Lazy::new(|| $crate::opentelemetry::global::meter(stringify!($name)));
|
||||
};
|
||||
($name:ident, $description:literal) => {
|
||||
static $name: once_cell::sync::Lazy<$crate::opentelemetry::metrics::Meter> =
|
||||
once_cell::sync::Lazy::new(|| $crate::opentelemetry::global::meter($description));
|
||||
($meter:ident, $name:literal) => {
|
||||
static $meter: once_cell::sync::Lazy<$crate::opentelemetry::metrics::Meter> =
|
||||
once_cell::sync::Lazy::new(|| $crate::opentelemetry::global::meter(stringify!($name)));
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a [`Counter`][Counter] metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be to a valid [`Meter`][Meter].
|
||||
/// associated with the specified meter. Note that the meter must be a valid [`Meter`][Meter].
|
||||
///
|
||||
/// [Counter]: opentelemetry::metrics::Counter
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
@ -36,36 +25,54 @@ macro_rules! counter_metric {
|
||||
($name:ident, $meter:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Counter<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_counter(stringify!($name)).init());
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_counter(stringify!($name)).build());
|
||||
};
|
||||
($name:ident, $meter:ident, description:literal) => {
|
||||
#[doc = $description]
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Counter<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_counter($description).init());
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.u64_counter(stringify!($name))
|
||||
.with_description($description)
|
||||
.build()
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a [`Histogram`][Histogram] metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be to a valid [`Meter`][Meter].
|
||||
/// Create a [`Histogram`][Histogram] f64 metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be a valid [`Meter`][Meter].
|
||||
///
|
||||
/// [Histogram]: opentelemetry::metrics::Histogram
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
#[macro_export]
|
||||
macro_rules! histogram_metric {
|
||||
macro_rules! histogram_metric_f64 {
|
||||
($name:ident, $meter:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<f64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.f64_histogram(stringify!($name)).init());
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.f64_histogram(stringify!($name))
|
||||
.with_boundaries($crate::metrics::f64_histogram_buckets())
|
||||
.build()
|
||||
});
|
||||
};
|
||||
($name:ident, $meter:ident, $description:literal) => {
|
||||
#[doc = $description]
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<f64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.f64_histogram($description).init());
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.f64_histogram(stringify!($name))
|
||||
.with_description($description)
|
||||
.with_boundaries($crate::metrics::f64_histogram_buckets())
|
||||
.build()
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a [`Histogram`][Histogram] u64 metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be to a valid [`Meter`][Meter].
|
||||
/// associated with the specified meter. Note that the meter must be a valid [`Meter`][Meter].
|
||||
///
|
||||
/// [Histogram]: opentelemetry::metrics::Histogram
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
@ -74,64 +81,72 @@ macro_rules! histogram_metric_u64 {
|
||||
($name:ident, $meter:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_histogram(stringify!($name)).init());
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.u64_histogram(stringify!($name))
|
||||
.with_boundaries($crate::metrics::f64_histogram_buckets())
|
||||
.build()
|
||||
});
|
||||
};
|
||||
($name:ident, $meter:ident, $description:literal) => {
|
||||
#[doc = $description]
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_histogram($description).init());
|
||||
> = once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.u64_histogram(stringify!($name))
|
||||
.with_description($description)
|
||||
.with_boundaries($crate::metrics::f64_histogram_buckets())
|
||||
.build()
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a [`Histogram`][Histogram] i64 metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be to a valid [`Meter`][Meter].
|
||||
/// Create a [`Gauge`][Gauge] metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be a valid [`Meter`][Meter].
|
||||
///
|
||||
/// [Histogram]: opentelemetry::metrics::Histogram
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
#[macro_export]
|
||||
macro_rules! histogram_metric_i64 {
|
||||
($name:ident, $meter:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<i64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.i64_histogram(stringify!($name)).init());
|
||||
};
|
||||
($name:ident, $meter:ident, $description:literal) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::Histogram<i64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.i64_histogram($description).init());
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a [`ObservableGauge`][ObservableGauge] metric with the specified name and an optional description,
|
||||
/// associated with the specified meter. Note that the meter must be to a valid [`Meter`][Meter].
|
||||
///
|
||||
/// [ObservableGauge]: opentelemetry::metrics::ObservableGauge
|
||||
/// [Gauge]: opentelemetry::metrics::Gauge
|
||||
/// [Meter]: opentelemetry::metrics::Meter
|
||||
#[macro_export]
|
||||
macro_rules! gauge_metric {
|
||||
($name:ident, $meter:ident) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::ObservableGauge<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_observable_gauge(stringify!($name)).init());
|
||||
pub(crate) static $name: once_cell::sync::Lazy<$crate::opentelemetry::metrics::Gauge<u64>> =
|
||||
once_cell::sync::Lazy::new(|| $meter.u64_gauge(stringify!($name)).build());
|
||||
};
|
||||
($name:ident, $meter:ident, description:literal) => {
|
||||
pub(crate) static $name: once_cell::sync::Lazy<
|
||||
$crate::opentelemetry::metrics::ObservableGauge<u64>,
|
||||
> = once_cell::sync::Lazy::new(|| $meter.u64_observable_gauge($description).init());
|
||||
#[doc = $description]
|
||||
pub(crate) static $name: once_cell::sync::Lazy<$crate::opentelemetry::metrics::Gauge<u64>> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
$meter
|
||||
.u64_gauge(stringify!($name))
|
||||
.with_description($description)
|
||||
.build()
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
pub use helpers::add_attributes;
|
||||
/// Create attributes to associate with a metric from key-value pairs.
|
||||
#[macro_export]
|
||||
macro_rules! metric_attributes {
|
||||
($(($key:expr, $value:expr $(,)?)),+ $(,)?) => {
|
||||
&[$($crate::opentelemetry::KeyValue::new($key, $value)),+]
|
||||
};
|
||||
}
|
||||
|
||||
pub use helpers::f64_histogram_buckets;
|
||||
|
||||
mod helpers {
|
||||
pub fn add_attributes<T, U>(attributes: U) -> Vec<opentelemetry::KeyValue>
|
||||
where
|
||||
T: Into<opentelemetry::Value>,
|
||||
U: IntoIterator<Item = (&'static str, T)>,
|
||||
{
|
||||
attributes
|
||||
.into_iter()
|
||||
.map(|(key, value)| opentelemetry::KeyValue::new(key, value))
|
||||
.collect::<Vec<_>>()
|
||||
/// Returns the buckets to be used for a f64 histogram
|
||||
#[inline(always)]
|
||||
pub fn f64_histogram_buckets() -> Vec<f64> {
|
||||
let mut init = 0.01;
|
||||
let mut buckets: [f64; 15] = [0.0; 15];
|
||||
|
||||
for bucket in &mut buckets {
|
||||
init *= 2.0;
|
||||
*bucket = init;
|
||||
}
|
||||
|
||||
Vec::from(buckets)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user