Description
Feature Request
Crates
tracing-subscriber
Motivation
A primary use-case for tracing-subscriber
's Layer
trait is to support teeing trace events between multiple consumers that implement different behaviors. When Layer
is used in this way, it should be possible to add filtering to Layer
s to allow the individual Layer
to decide what spans and events it is interested in recording, without disabling those spans/events for the entire stack.
Currently, however, the register_callsite
and enabled
methods on Layer
are designed to support a use-case where a layer does deny or accept events for the whole stack. This is intended to allow a Layer
to globally disable spans and events to support a use-case where a single filter is used for the whole stack, or use-cases such as rate-limiting etc.
This should probably be revisited. Ideally, it would be possible to support both use-cases without adding too much more additional complexity to the interface.
Design Questions
There are some design questions that should inform a solution to this problem.
- Are users interested in global filtering/sampling? The current design makes the assumption that users of
tracing-subscriber
want to be able to add a single filter/sampler layer to a stack that controls the behaviour of the entire composed subscriber. Is this actually the case? In a scenario where multiple layers that implement different ways of recording trace events (e.g. logging, metrics, etc) or output to different sinks (e.g., logging to a file, stderr, and stdout), will users want to have a global filter configuration that applies to all of these? And if so, is this common enough that we should optimize for it? - Should
Layer::enabled
be used for per-layer filtering? Or, should a new trait method be added? Having two similar but different methods sounds potentially confusing. - Are we okay with
Layer::enabled
being called multiple times for the same event? - How to reconcile this with callsite
Interest
caching?