mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
refactor(storage): remove id from payment intent, attempt and remove datamodel ext from payment intent (#4923)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Prajjwal Kumar <prajjwal.kumar@juspay.in>
This commit is contained in:
@ -30,6 +30,9 @@ pub mod static_cache;
|
||||
pub mod types;
|
||||
pub mod validation;
|
||||
|
||||
#[cfg(feature = "metrics")]
|
||||
pub mod metrics;
|
||||
|
||||
/// Date-time utilities.
|
||||
pub mod date_time {
|
||||
#[cfg(feature = "async_ext")]
|
||||
|
||||
2
crates/common_utils/src/metrics.rs
Normal file
2
crates/common_utils/src/metrics.rs
Normal file
@ -0,0 +1,2 @@
|
||||
//! Utilities for metrics
|
||||
pub mod utils;
|
||||
33
crates/common_utils/src/metrics/utils.rs
Normal file
33
crates/common_utils/src/metrics/utils.rs
Normal file
@ -0,0 +1,33 @@
|
||||
//! metric utility functions
|
||||
|
||||
use std::time;
|
||||
|
||||
use router_env::opentelemetry;
|
||||
|
||||
/// Record the time taken by the future to execute
|
||||
#[inline]
|
||||
pub async fn time_future<F, R>(future: F) -> (R, time::Duration)
|
||||
where
|
||||
F: futures::Future<Output = R>,
|
||||
{
|
||||
let start = time::Instant::now();
|
||||
let result = future.await;
|
||||
let time_spent = start.elapsed();
|
||||
(result, time_spent)
|
||||
}
|
||||
|
||||
/// Record the time taken (in seconds) by the operation for the given context
|
||||
#[inline]
|
||||
pub async fn record_operation_time<F, R>(
|
||||
future: F,
|
||||
metric: &opentelemetry::metrics::Histogram<f64>,
|
||||
metric_context: &opentelemetry::Context,
|
||||
key_value: &[opentelemetry::KeyValue],
|
||||
) -> R
|
||||
where
|
||||
F: futures::Future<Output = R>,
|
||||
{
|
||||
let (result, time) = time_future(future).await;
|
||||
metric.record(metric_context, time.as_secs_f64(), key_value);
|
||||
result
|
||||
}
|
||||
Reference in New Issue
Block a user