tracing-fluent-assertions
A fluent assertions framework for tracing
.
overview
While there are already many crates that deal with testing -- mocks, test doubles, advanced
assertions, etc -- there aren't any crates that allow a user to understand how their
tracing
implementation is exercised at a holistic level. While there
are some crates, like tracing-test
, which exist for figuring out
if a chunk of code emitted certain events, there is no generic way to ask questions like:
- was span A ever created? or entered?
- did it ever close?
- did it enter/exit/close at least N times?
- did any spans in module path X ever get created?
This is the problem that tracing-fluent-assertions
aims to solve.
usage
This crate doesn't look terribly dissimilar to other crates which provide fluent assertions, but as it's oriented around spans, which are callsite-defined, there's a little bit of boilerplate involved in using it compared to defining assertions directly against the result of a function, and so on.
Firstly, it provides a Subscriber
layer that must be installed so that it can intercept span events and track the lifecycle of spans.
Secondly, an
AssertionRegistry
is provided for creating and storing assertions.
An
Assertion
defines what spans it should match, and what behavior the spans must match in order to assert
successfully.
A condensed usage might look something like this:
use ;
use ;