🛈 Note: This is pre-release documentation for the upcoming tracing 0.2.0 ecosystem.

For the release documentation, please see docs.rs, instead.

tracing_mock::expect

Function span

Source
pub fn span() -> ExpectedSpan
Expand description

Construct a new ExpectedSpan.

For details on how to add additional assertions to the expected span, see the span module and the ExpectedSpan and NewSpan structs.

§Examples

use tracing_mock::{collector, expect};

let (collector, handle) = collector::mock()
    .new_span(expect::span())
    .enter(expect::span())
    .run_with_handle();

tracing::collect::with_default(collector, || {
    let span = tracing::info_span!("span");
    let _guard = span.enter();
});

handle.assert_finished();

If we expect to enter a span and instead record something else, the test will fail:

use tracing_mock::{collector, expect};

let (collector, handle) = collector::mock()
    .enter(expect::span())
    .run_with_handle();

tracing::collect::with_default(collector, || {
    tracing::info!(field.name = "field_value");
});

handle.assert_finished();