From 81d1464d7ab4b67031692ae81cabb212869489e6 Mon Sep 17 00:00:00 2001 From: kosuke-fujishiro Date: Thu, 22 Jan 2026 16:13:57 +0900 Subject: [PATCH] fix: spawn process metrics as background task init_process_observer runs an infinite loop to collect system metrics, so it must be spawned as a background task instead of being awaited. Also add gzip-tonic feature for OTLP compression support. Co-Authored-By: Claude Opus 4.5 --- Cargo.lock | 1 + Cargo.toml | 1 + src/cli/metrics.rs | 16 ++++++++++------ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 209f542f0b..7c3f0aa079 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6179,6 +6179,7 @@ dependencies = [ "axum", "base64 0.22.1", "bytes", + "flate2", "h2 0.4.13", "http 1.4.0", "http-body 1.0.1", diff --git a/Cargo.toml b/Cargo.toml index d926bc2eec..247ef3ccb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -170,6 +170,7 @@ opentelemetry-otlp = { version = "0.28", features = [ "metrics", # required to make grpc requests "grpc-tonic", + "gzip-tonic", "tls-roots", ], optional = true } opentelemetry-prometheus = "0.28" diff --git a/src/cli/metrics.rs b/src/cli/metrics.rs index edcda325ec..267f1ff8ee 100644 --- a/src/cli/metrics.rs +++ b/src/cli/metrics.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Result}; +use anyhow::Result; use crate::core::runtime::TargetRuntime; @@ -18,17 +18,21 @@ fn cache_metrics(runtime: &TargetRuntime) -> Result<()> { Ok(()) } -async fn process_resources_metrics() -> Result<()> { +fn process_resources_metrics() { let meter = opentelemetry::global::meter("process-resources"); - opentelemetry_system_metrics::init_process_observer(meter) - .await - .map_err(|err| anyhow!(err)) + // init_process_observer runs an infinite loop to collect system metrics, + // so it must be spawned as a background task + tokio::spawn(async move { + if let Err(err) = opentelemetry_system_metrics::init_process_observer(meter).await { + tracing::warn!("process_resources_metrics failed: {}", err); + } + }); } pub async fn init_metrics(runtime: &TargetRuntime) -> Result<()> { cache_metrics(runtime)?; - process_resources_metrics().await?; + process_resources_metrics(); Ok(()) }