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 committed Nov 7, 2024
1 parent f9c5212 commit fd0ff1d
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions bridge/svix-bridge/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,33 +279,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 fd0ff1d

Please sign in to comment.