Skip to content

Commit

Permalink
refactor(test): clean up before_test_async()
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jun 14, 2024
1 parent 7d18f92 commit e919914
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
3 changes: 1 addition & 2 deletions rustup-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn test_inner(mod_path: String, mut input: ItemFn) -> syn::Result<TokenStream> {
let name = input.sig.ident.clone();
let new_block: Block = parse_quote! {
{
let _guard = #before_ident().await;
#before_ident().await;
// Define a function with same name we can instrument inside the
// tracing enablement logic.
#[cfg_attr(feature = "otel", tracing::instrument(skip_all))]
Expand All @@ -118,7 +118,6 @@ fn test_inner(mod_path: String, mut input: ItemFn) -> syn::Result<TokenStream> {
input.block = Box::new(new_block);

Ok(quote! {
#[cfg_attr(feature = "otel", tracing::instrument(skip_all))]
#[::tokio::test(flavor = "multi_thread", worker_threads = 1)]
#input
})
Expand Down
21 changes: 4 additions & 17 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,12 @@ where
f(&rustup_home)
}

pub async fn before_test_async() -> Option<tracing::dispatcher::DefaultGuard> {
pub async fn before_test_async() {
#[cfg(feature = "otel")]
{
use tracing_subscriber::{layer::SubscriberExt, Registry};

let telemetry = {
use opentelemetry::global;
use opentelemetry_sdk::propagation::TraceContextPropagator;

global::set_text_map_propagator(TraceContextPropagator::new());
crate::cli::log::telemetry()
};

let subscriber = Registry::default().with(telemetry);
Some(tracing::subscriber::set_default(subscriber))
}
#[cfg(not(feature = "otel"))]
{
None
opentelemetry::global::set_text_map_propagator(
opentelemetry_sdk::propagation::TraceContextPropagator::new(),
);
}
}

Expand Down

0 comments on commit e919914

Please sign in to comment.