A macro and utilities to do snapshot tests on tracing spans.
Refer to the tests for a more exhaustive list of features and behaviors:
```rust use test_span::prelude::*;
fn atest() { dosomething();
// test_span provides your with three functions:
let spans = get_spans();
let logs = get_logs();
// you can get both in one call
let (spans, logs) = get_telemetry();
// This plays well with insta snapshots:
insta::assert_json_snapshot!(logs);
insta::assert_json_snapshot!(spans);
}
// Test span plays well with async
// you can specify the span / log level // you would like to track like this:
async fn ansynctest() { dosomethingasync().await; // You still get access to each function let spans = getspans(); let logs = getlogs(); let (spans, logs) = get_telemetry(); } ```
Spans and logs are hard to track across thread spawns. However we're providing you with a log dump you can check:
```rust
fn trackacrossthreads() { std::thread::spawn(|| { tracing::info!("only in getalllogs!"); }) .join() .unwrap();
let logs = get_logs();
// not in get_logs()
assert!(!logs.contains_message("only in get_all_logs!");
// get_all_logs takes a filter Level
let all_logs = test_span::get_all_logs(&tracing::Level::INFO);
assert!(all_logs.contains_message("only in get_all_logs!"));
} ```
More information can be found in the contribution docs
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.