Skip to content

Commit 580c94f

Browse files
committed
refactor(test): replace (before|after)_test_async() with TestProcess::_telemetry_guard
1 parent 3152eee commit 580c94f

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

src/process.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ use tracing_subscriber::util::SubscriberInitExt;
2020
#[cfg(feature = "test")]
2121
use tracing_subscriber::{EnvFilter, Registry, reload::Handle};
2222

23+
#[cfg(all(feature = "test", feature = "otel"))]
24+
use crate::cli::log;
25+
2326
pub mod filesource;
2427
pub mod terminalsource;
2528

@@ -180,7 +183,10 @@ impl Default for OsProcess {
180183
pub struct TestProcess {
181184
pub process: Process,
182185
pub console_filter: Handle<EnvFilter, Registry>,
183-
_tracing_guard: DefaultGuard, // guard is dropped at the end of the test
186+
// These guards are dropped _in order_ at the end of the test.
187+
#[cfg(feature = "otel")]
188+
_telemetry_guard: log::GlobalTelemetryGuard,
189+
_tracing_guard: DefaultGuard,
184190
}
185191

186192
#[cfg(feature = "test")]
@@ -237,6 +243,8 @@ impl From<TestContext> for TestProcess {
237243
Self {
238244
process: inner,
239245
console_filter,
246+
#[cfg(feature = "otel")]
247+
_telemetry_guard: log::set_global_telemetry(),
240248
_tracing_guard: tracing_subscriber.set_default(),
241249
}
242250
}

src/test.rs

-19
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,3 @@ where
231231
let rustup_home = RustupHome::new_in(test_dir)?;
232232
f(&rustup_home)
233233
}
234-
235-
pub async fn before_test_async() {
236-
#[cfg(feature = "otel")]
237-
{
238-
opentelemetry::global::set_text_map_propagator(
239-
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
240-
);
241-
}
242-
}
243-
244-
pub async fn after_test_async() {
245-
#[cfg(feature = "otel")]
246-
{
247-
// We're tracing, so block until all spans are exported.
248-
opentelemetry::global::set_tracer_provider(
249-
opentelemetry::trace::noop::NoopTracerProvider::new(),
250-
);
251-
}
252-
}

0 commit comments

Comments
 (0)