PrometheusBuilder::install: Build exporter in runtime context

Closes https://github.com/metrics-rs/metrics/issues/122
This commit is contained in:
str4d 2020-11-11 15:34:30 +00:00 committed by GitHub
parent fbd603582e
commit 01fcc020c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -443,14 +443,14 @@ impl PrometheusBuilder {
/// installing the recorder as the global recorder.
#[cfg(feature = "tokio-exporter")]
pub fn install(self) -> Result<(), Error> {
let (recorder, exporter) = self.build_with_exporter()?;
metrics::set_boxed_recorder(Box::new(recorder))?;
let mut runtime = runtime::Builder::new()
.basic_scheduler()
.enable_all()
.build()?;
let (recorder, exporter) = runtime.enter(|| self.build_with_exporter())?;
metrics::set_boxed_recorder(Box::new(recorder))?;
thread::Builder::new()
.name("metrics-exporter-prometheus-http".to_string())
.spawn(move || {