Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! fixup! fixup! refactor(log): reimplement …
Browse files Browse the repository at this point in the history
…`log` using `tracing`
  • Loading branch information
rami3l committed Jun 2, 2024
1 parent 653f8cc commit 54f078c
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ use once_cell::sync::Lazy;

/// A tokio runtime for the sync tests, permitting the use of tracing. This is
/// never shutdown, instead it is just dropped at end of process.
#[cfg(feature = "otel")]
static TRACE_RUNTIME: Lazy<tokio::runtime::Runtime> =
Lazy::new(|| tokio::runtime::Runtime::new().unwrap());

Expand All @@ -239,16 +240,13 @@ type Tracer = ();

/// A tracer for the tests.
pub(crate) static TRACER: Lazy<Tracer> = Lazy::new(|| {
use tracing_subscriber::Registry;

#[cfg(feature = "otel")]
{
use crate::cli::log::{telemetry, telemetry_default_tracer};
use crate::cli::log::telemetry_default_tracer;

use opentelemetry::global;
use opentelemetry_sdk::propagation::TraceContextPropagator;
use tokio::runtime::Handle;
use tracing_subscriber::layer::SubscriberExt as _;

// Use the current runtime, or the sync test runtime otherwise.
let handle = match Handle::try_current() {
Expand All @@ -259,16 +257,7 @@ pub(crate) static TRACER: Lazy<Tracer> = Lazy::new(|| {
let _guard = handle.enter();

global::set_text_map_propagator(TraceContextPropagator::new());
let tracer = telemetry_default_tracer().unwrap();
let telemetry = telemetry(tracer.clone());
let subscriber = Registry::default().with(telemetry);
tracing::subscriber::set_global_default(subscriber).unwrap();
tracer
}
#[cfg(not(feature = "otel"))]
{
let subscriber = Registry::default();
tracing::subscriber::set_global_default(subscriber).unwrap();
telemetry_default_tracer().unwrap()
}
});

Expand Down

0 comments on commit 54f078c

Please sign in to comment.