Testing tracing in tokio

Hello,

an application I am maintaining is using tracing and tokio.

The application itself is quite successful and tracing is used for logs and metrics.

Those metrics:

  1. Drive quite a bit of value, and
  2. Can wake up fellow engineers at night

It is natural that we are trying to add testing also for tracing.

However, I am finding it quite challenging.

Ideally I would like to start something at the very beginning of the unittest, carry out the test logic, and get all the events that have been emitted.

Then I would be able to assert on those events.

What would be the best way to implement this?

you'll need to create a "mock" subscriber for that, and run the test code with the it.

for simple test code, you can use:

for async scenario, you can wrap the future with the instrumentation:


update: just found this crate:

1 Like