Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
subscriber: add Filter and Reload layers (#223)
## Motivation Currently, `tracing-fmt` provides an implementation of `env_logger`-like filtering directives. However, there are two issues: 1. The implementation is specific to `tracing-fmt` and does not work with other subscribers. 2. Filtering dynamically based on field values is not supported. Now that the `Layer` type has been added to `tracing-subscriber` (see #136), we can implement filtering generically, as a `Layer` that can wrap other `Subscriber`s to provide a particular filtering strategy. ## Solution This branch re-implements the `env_logger` style filtering in `tracing-fmt` as a `tracing-subscriber::Layer`. The new `Layer` type implements dynamic filtering on span fields, in addition to the functionality of the `tracing-fmt` implementation. I've also added a wrapper type to support runtime reloading of a `Layer`, similarly to the `Reload` type in `tracing-fmt::filter`, but more general. Finally, I've added some tests and an interactive demo for the new filtering. The example runs a simple web service with a load generator, and allows users to explore the `tracing-fmt` output from the example service by dynamically reloading the filter settings. ## Notes This is admittedly a pretty large branch, but I think it makes the most sense to merge everything together, since the example requires both the filter implementation *and* the reload layer. I've tried to make sure the most complex bits of the filtering code has comments describing the implementation, but please let me know if anything is unclear. Also, there is a lot of room for potential performance improvements in the current filter implementation. I've left comments on some code that I think could probably be made more efficient. Ideally, though, any future optimization work ought to be guided by benchmarks as well. Signed-off-by: Eliza Weisman <[email protected]> Signed-off-by: Eliza Weisman <[email protected]>
- Loading branch information