test-span
A macro and utilities to do snapshot tests on tracing spans.
How to use
Refer to the tests for a more exhaustive list of features and behaviors:
use test_span::prelude::*;
#[test_span]
fn a_test() {
do_something();
let spans = get_spans();
let logs = get_logs();
let (spans, logs) = get_telemetry();
insta::assert_json_snapshot!(logs);
insta::assert_json_snapshot!(spans);
}
#[test_span(tokio::test)]
#[level(tracing::Level::INFO)]
async fn an_sync_test() {
do_something_async().await;
let spans = get_spans();
let logs = get_logs();
let (spans, logs) = get_telemetry();
}
Limitations
Spans and logs are hard to track across thread spawns. However we're providing you with a log dump you can check:
#[test_span]
fn track_across_threads() {
std::thread::spawn(|| {
tracing::info!("only in get_all_logs!");
})
.join()
.unwrap();
let logs = get_logs();
assert!(!logs.contains_message("only in get_all_logs!");
let all_logs = test_span::get_all_logs(&tracing::Level::INFO);
assert!(all_logs.contains_message("only in get_all_logs!"));
}
Contributing
More information can be found in the contribution docs
License