diff --git a/common/task_executor/src/lib.rs b/common/task_executor/src/lib.rs index abf8e7834..0e15e16e0 100644 --- a/common/task_executor/src/lib.rs +++ b/common/task_executor/src/lib.rs @@ -96,6 +96,7 @@ impl TaskExecutor { if let Some(runtime) = self.runtime.upgrade() { runtime.spawn(async move { + let timer = metrics::start_timer_vec(&metrics::TASKS_HISTOGRAM, &[name]); if let Err(join_error) = task_handle.await { if let Ok(panic) = join_error.try_into_panic() { let message = panic.downcast_ref::<&str>().unwrap_or(&""); @@ -112,6 +113,7 @@ impl TaskExecutor { .try_send(ShutdownReason::Failure("Panic (fatal error)")); } } + drop(timer); }); } else { debug!( diff --git a/common/task_executor/src/metrics.rs b/common/task_executor/src/metrics.rs index 54f4b93c8..ead5925b6 100644 --- a/common/task_executor/src/metrics.rs +++ b/common/task_executor/src/metrics.rs @@ -18,4 +18,9 @@ lazy_static! { "Time taken by blocking tasks", &["blocking_task_hist"] ); + pub static ref TASKS_HISTOGRAM: Result = try_create_histogram_vec( + "async_tasks_time_histogram", + "Time taken by async tasks", + &["async_task_hist"] + ); }