Skip to content

Commit 84a91d5

Browse files
authored
Subscribe to traces for live tests (Azure#2341)
* Subscribe to traces for live tests * Fix lint
1 parent 31f43ea commit 84a91d5

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

sdk/core/azure_core_test/src/recorded.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use std::sync::Arc;
1313
#[cfg(not(target_arch = "wasm32"))]
1414
use tokio::sync::OnceCell;
1515

16+
#[cfg(not(target_arch = "wasm32"))]
17+
static ONLY_TRACE: std::sync::OnceLock<()> = std::sync::OnceLock::new();
18+
1619
#[cfg(not(target_arch = "wasm32"))]
1720
static TEST_PROXY: OnceCell<Result<Arc<Proxy>>> = OnceCell::const_new();
1821

@@ -36,19 +39,14 @@ pub async fn start(
3639
#[cfg(not(target_arch = "wasm32"))]
3740
let proxy = {
3841
match mode {
39-
TestMode::Live => None,
42+
TestMode::Live => {
43+
ONLY_TRACE.get_or_init(init_tracing);
44+
None
45+
}
4046
_ => Some(
4147
TEST_PROXY
4248
.get_or_init(|| async move {
43-
#[cfg(feature = "tracing")]
44-
{
45-
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};
46-
tracing_subscriber::fmt()
47-
.with_env_filter(EnvFilter::from_default_env())
48-
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
49-
.init();
50-
}
51-
49+
init_tracing();
5250
crate::proxy::start(Some(mode), crate_dir, options)
5351
.await
5452
.map(Arc::new)
@@ -82,3 +80,16 @@ pub async fn start(
8280
ctx.recording = Some(recording);
8381
Ok(ctx)
8482
}
83+
84+
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
85+
fn init_tracing() {
86+
#[cfg(feature = "tracing")]
87+
{
88+
use tracing_subscriber::{fmt::format::FmtSpan, EnvFilter};
89+
tracing_subscriber::fmt()
90+
.with_env_filter(EnvFilter::from_default_env())
91+
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
92+
.with_writer(std::io::stderr)
93+
.init();
94+
}
95+
}

0 commit comments

Comments
 (0)