Skip to content

Commit 8f455ee

Browse files
committed
Enable tracing logging in factors tests
This gives more output when debugging test failures. Signed-off-by: Lann Martin <[email protected]>
1 parent 40e88fa commit 8f455ee

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

crates/factors-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = { workspace = true }
88
spin-app = { path = "../app" }
99
spin-factors = { path = "../factors" }
1010
spin-loader = { path = "../loader" }
11+
spin-telemetry = { path = "../telemetry", features = ["testing"] }
1112
tempfile = { workspace = true }
1213
toml = { workspace = true }
1314

crates/factors-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ impl<T: RuntimeFactors> TestEnvironment<T> {
2222
/// Creates a new test environment by initializing the given
2323
/// [`RuntimeFactors`].
2424
pub fn new(mut factors: T) -> Self {
25+
spin_telemetry::testing::init_test_telemetry();
26+
2527
let engine = Engine::new(Config::new().async_support(true))
2628
.expect("wasmtime engine failed to initialize");
2729
let mut linker = Linker::<T::InstanceState>::new(&engine);

crates/telemetry/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ tracing-opentelemetry = { version = "0.29", default-features = false, features =
1818
tracing-subscriber = { version = "0.3", default-features = false, features = ["smallvec", "fmt", "ansi", "std", "env-filter", "json", "registry"] }
1919

2020
[features]
21+
testing = []
2122
tracing-log-compat = ["tracing-subscriber/tracing-log", "tracing-opentelemetry/tracing-log"]

crates/telemetry/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pub mod metrics;
1515
mod propagation;
1616
mod traces;
1717

18+
#[cfg(feature = "testing")]
19+
pub mod testing;
20+
1821
pub use propagation::extract_trace_context;
1922
pub use propagation::inject_trace_context;
2023

crates/telemetry/src/testing.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// Initializes telemetry integration for libtest environments.
2+
pub fn init_test_telemetry() {
3+
static ONCE: std::sync::Once = std::sync::Once::new();
4+
ONCE.call_once(|| {
5+
if let Err(err) = tracing_subscriber::fmt().with_test_writer().try_init() {
6+
eprintln!("init_test_telemetry failed to init global tracing_subscriber: {err:?}");
7+
}
8+
});
9+
}

0 commit comments

Comments
 (0)