mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 19:21:13 +00:00
Telemetry per node (#7463)
This commit is contained in:
@@ -34,6 +34,7 @@ use prometheus_endpoint::{
|
||||
use sp_utils::mpsc::{TracingUnboundedSender, TracingUnboundedReceiver, tracing_unbounded};
|
||||
use tracing_futures::Instrument;
|
||||
use crate::{config::{TaskExecutor, TaskType, JoinFuture}, Error};
|
||||
use sc_telemetry::TelemetrySpan;
|
||||
|
||||
mod prometheus_future;
|
||||
#[cfg(test)]
|
||||
@@ -46,6 +47,7 @@ pub struct SpawnTaskHandle {
|
||||
executor: TaskExecutor,
|
||||
metrics: Option<Metrics>,
|
||||
task_notifier: TracingUnboundedSender<JoinFuture>,
|
||||
telemetry_span: Option<TelemetrySpan>,
|
||||
}
|
||||
|
||||
impl SpawnTaskHandle {
|
||||
@@ -89,7 +91,10 @@ impl SpawnTaskHandle {
|
||||
metrics.tasks_ended.with_label_values(&[name, "finished"]).inc_by(0);
|
||||
}
|
||||
|
||||
let telemetry_span = self.telemetry_span.clone();
|
||||
let future = async move {
|
||||
let _telemetry_entered = telemetry_span.as_ref().map(|x| x.enter());
|
||||
|
||||
if let Some(metrics) = metrics {
|
||||
// Add some wrappers around `task`.
|
||||
let task = {
|
||||
@@ -228,14 +233,17 @@ pub struct TaskManager {
|
||||
/// terminates and gracefully shutdown. Also ends the parent `future()` if a child's essential
|
||||
/// task fails.
|
||||
children: Vec<TaskManager>,
|
||||
/// A telemetry handle used to enter the telemetry span when a task is spawned.
|
||||
telemetry_span: Option<TelemetrySpan>,
|
||||
}
|
||||
|
||||
impl TaskManager {
|
||||
/// If a Prometheus registry is passed, it will be used to report statistics about the
|
||||
/// service tasks.
|
||||
/// If a Prometheus registry is passed, it will be used to report statistics about the
|
||||
/// service tasks.
|
||||
pub(super) fn new(
|
||||
executor: TaskExecutor,
|
||||
prometheus_registry: Option<&Registry>
|
||||
prometheus_registry: Option<&Registry>,
|
||||
telemetry_span: Option<TelemetrySpan>,
|
||||
) -> Result<Self, PrometheusError> {
|
||||
let (signal, on_exit) = exit_future::signal();
|
||||
|
||||
@@ -264,6 +272,7 @@ impl TaskManager {
|
||||
task_notifier,
|
||||
completion_future,
|
||||
children: Vec::new(),
|
||||
telemetry_span,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -274,6 +283,7 @@ impl TaskManager {
|
||||
executor: self.executor.clone(),
|
||||
metrics: self.metrics.clone(),
|
||||
task_notifier: self.task_notifier.clone(),
|
||||
telemetry_span: self.telemetry_span.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user