From 2261e266da6b8e6218757aaa857c57c04ae29d78 Mon Sep 17 00:00:00 2001 From: rami3l Date: Tue, 18 Jun 2024 10:49:04 +0800 Subject: [PATCH] refactor(log): replace the `TELEMETRY_DEFAULT_TARCER` singleton with a function --- src/cli/log.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/cli/log.rs b/src/cli/log.rs index b9d59df6a3..4bb7fc227f 100644 --- a/src/cli/log.rs +++ b/src/cli/log.rs @@ -11,8 +11,6 @@ use tracing_subscriber::{ EnvFilter, Layer, }; -#[cfg(feature = "otel")] -use once_cell::sync::Lazy; #[cfg(feature = "otel")] use opentelemetry_sdk::trace::Tracer; @@ -131,16 +129,16 @@ where EnvFilter::new("rustup=TRACE") }; tracing_opentelemetry::layer() - .with_tracer(TELEMETRY_DEFAULT_TRACER.clone()) + .with_tracer(telemetry_default_tracer()) .with_filter(env_filter) } /// The default `opentelemetry` tracer used across Rustup. /// /// # Note -/// The initializer function will panic if not called within the context of a [`tokio`] runtime. +/// This function will panic if not called within the context of a [`tokio`] runtime. #[cfg(feature = "otel")] -static TELEMETRY_DEFAULT_TRACER: Lazy = Lazy::new(|| { +fn telemetry_default_tracer() -> Tracer { use std::time::Duration; use opentelemetry::KeyValue; @@ -164,4 +162,4 @@ static TELEMETRY_DEFAULT_TRACER: Lazy = Lazy::new(|| { ) .install_batch(opentelemetry_sdk::runtime::Tokio) .expect("error installing `OtlpTracePipeline` in the current `tokio` runtime") -}); +}