Skip to content

Commit

Permalink
Flush metrics on span exit
Browse files Browse the repository at this point in the history
This is wasteful, but is required for tests only
  • Loading branch information
akoshelev committed Sep 17, 2024
1 parent 3ff5ed5 commit a54e0dd
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ipa-metrics-tracing/src/layer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::fmt::Debug;

use ipa_metrics::MetricsCurrentThreadContext;
use tracing::{
field::{Field, Visit},
instrument::WithSubscriber,
Expand Down Expand Up @@ -59,6 +60,13 @@ impl<S: Subscriber + for<'s> LookupSpan<'s>> Layer<S> for MetricsPartitioningLay
ipa_metrics::set_or_unset_partition(prev.take())
};
}

fn on_close(&self, id: Id, ctx: Context<'_, S>) {
let span = ctx.span(&id).expect("Span should exists before closing it");
if let Some(MetricPartition(_, _)) = span.extensions().get() {
MetricsCurrentThreadContext::flush();
};
}
}

#[cfg(test)]
Expand Down

0 comments on commit a54e0dd

Please sign in to comment.