Expand description
the test span library provides you with two functions:
get_logs()
that returns [prelude::Records
]
get_span()
that returns a [prelude::Span
],
Which can be serialized and used with insta for snapshot tests.
Refer to the tests.rs file to see how it behaves.
Example:
ⓘ
#[test_span]
async fn test_it_works() {
futures::join!(do_stuff(), do_stuff())
}
#[tracing::instrument(name = "do_stuff", level = "info")]
async fn do_stuff() -> u8 {
// ...
do_stuff2().await;
}
#[tracing::instrument(
name = "do_stuff2",
target = "my_crate::an_other_target",
level = "info"
)]
async fn do_stuff_2(number: u8) -> u8 {
// ...
}
`get_span()` will provide you with:
┌──────┐
│ root │
└──┬───┘
│
┌───────┴───────┐
▼ ▼
┌──────────┐ ┌──────────┐
│ do_stuff │ │ do_stuff │
└────┬─────┘ └─────┬────┘
│ │
│ │
▼ ▼
┌───────────┐ ┌───────────┐
│ do_stuff2 │ │ do_stuff2 │
└───────────┘ └───────────┘
Modules§
Structs§
- Filter
- Layer
- Records
- A Vec of log entries.
- Report
- Span
- A tree which is effectively a Tree containing all the spans
Enums§
Functions§
- get_
all_ logs - Unlike its
get_logs
counterpart provided by the trace_span macro,get_all_logs
will return all of the module’s tests logs. - get_
logs_ for_ root - Returns Records, which is a Vec, containing all entries recorded by children of
root_id
. - get_
spans_ for_ root - Returns a
Span
, a Tree containing all the spans that are children ofroot_id
. - get_
telemetry_ for_ root - Returns both the output of
get_spans_for_root
andget_logs_for_root
- init
init_default
is the default way to callwith_targets
, it sets upLevel::INFO
and looks for environment variables to filter spans.