Skip to content

Commit

Permalink
Bridge: remove long-living span around metrics collection
Browse files Browse the repository at this point in the history
Long-living tracing spans can leak memory over time if logs happen to be
produced inside them.

Removing the span should help avoid a leak later.
  • Loading branch information
svix-onelson authored and svix-james committed Nov 8, 2024
1 parent f9b6c1c commit d3a90b0
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions bridge/svix-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use svix_bridge_types::{PollerInput, SenderInput, TransformerJob};
use svix_ksuid::{KsuidLike as _, KsuidMs};
#[cfg(all(not(target_env = "msvc"), feature = "jemalloc"))]
use tikv_jemallocator::Jemalloc;
use tracing::Instrument;
use tracing_subscriber::{layer::SubscriberExt as _, util::SubscriberInitExt as _};

use self::config::Config;
Expand Down Expand Up @@ -279,33 +278,26 @@ async fn main() -> Result<()> {
let _metrics = setup_metrics(&cfg);
tracing::info!("starting");

tokio::spawn(
async move {
let mut interval = tokio::time::interval(Duration::from_secs(15));
let metrics = CommonMetrics::new(&opentelemetry::global::meter("svix.com"));
match get_allocator_stat_mibs() {
Ok(mibs) => {
tracing::debug!("Common Metrics Collection: Started");

loop {
interval.tick().await;

if let Ok(Some((allocated, resident))) =
get_allocator_stats(true, mibs.clone())
{
metrics.record_mem_allocated(allocated as _);
metrics.record_mem_resident(resident as _);
}
tokio::spawn(async move {
let mut interval = tokio::time::interval(Duration::from_secs(15));
let metrics = CommonMetrics::new(&opentelemetry::global::meter("svix.com"));
match get_allocator_stat_mibs() {
Ok(mibs) => {
tracing::debug!("Common Metrics Collection: Started");

loop {
interval.tick().await;

if let Ok(Some((allocated, resident))) = get_allocator_stats(true, mibs.clone())
{
metrics.record_mem_allocated(allocated as _);
metrics.record_mem_resident(resident as _);
}
}
Err(e) => tracing::error!("Unable to get allocator stats mibs: {e}"),
}
Err(e) => tracing::error!("Unable to get allocator stats mibs: {e}"),
}
.instrument(tracing::error_span!(
"common_metrics_collector",
instance_id = tracing::field::Empty
)),
);
});

let (xform_tx, mut xform_rx) = tokio::sync::mpsc::unbounded_channel::<TransformerJob>();

Expand Down

0 comments on commit d3a90b0

Please sign in to comment.