Skip to content

MetricsLayer forces callsites to register as Interest::sometimes() since it is not a Filtered #111

@xuorig

Description

@xuorig

The MetricsLayer structure, which wraps an inner Filtered itself implements Layer.

The Filtered structure always returns always and let's the Registry decide on the "combined" final interest. However, in this case, while the MetricsLayer does call inner.register_callsite, the MetricsLayer itself is not a Filtered.

tracing-subscriber is not able to understand that MetricsLayer is in fact a per-layer filter, and this always is actually treated as a layer returning always. In turn, the registry decides to return sometimes() for the callsite (https://github.com/tokio-rs/tracing/blob/0e3577f6f3995b92accee21e0737c25ef0f1953c/tracing-subscriber/src/subscribe/layered.rs#L463-L472)

I believe this is a bug. I'd be happy to contribute a fix to this but I'd love to discuss how to best design this. One option is to let the users build the filtered themselves. The other is to have some sort of API that returns an actual Filtered. I'm not exactly sure if there's a way to make this work through the Layer implementation, maybe using on_layer?

Using instrument_layer.with_filter(MetricsFilter) directly fixes the issue, but both these structures are private.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions