Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscriber: add new_span, on_enter, on_exit, and on_close hooks to Filter #1955

Closed
hawkw opened this issue Feb 22, 2022 · 0 comments
Closed
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/feature New feature or request

Comments

@hawkw
Copy link
Member

hawkw commented Feb 22, 2022

Feature Request

Crates

  • tracing-subscriber

Motivation

Currently, if a Filter is going to implement dynamic filtering, it must do this by querying the wrapped Subscriber for the current span context. Since Filter only has callsite_enabled and enabled methods, a Filter implementation cannot track the span context internally, the way a Layer can.

Unfortunately, this means that the current implementation of EnvFilter can only implement Layer (and provide global filtering). It cannot currently implement Filter, because it stores span context data internally. See #1868 for details.

Proposal

We should add on_new_span, on_enter, on_exit, and on_close methods to Filter. This would allow implementing Filters (such as EnvFilter) that internally track span states.

Alternatives

There are essentially two other options for implementing Filter for EnvFilter:

  • We could rewrite the implementation to use the LookupSpan APIs to store span data in the registry, and query that instead of internally. This might potentially require a breaking change, as EnvFilter would require the Subscriber to implement LookupSpan.

    Another hurdle is that the way EnvFilter is currently implemented also requires a new_span notification. Currently, the Filter trait cannot store data for a span when that span is created, even if that data is used for filtering later. This is because it only receives enabled method calls when spans are created. It cannot store data in the span for filtering events, because the span has not yet been created yet. Potentially, if we prefer to make a smaller, more targeted modification to the Filter trait, we could just add a new_span method.

  • Or, we could use an approach where the EnvFilter is shared between a struct implementing Filter and a struct implementing Layer, where the Layer does not perform any actual filtering, but simply mutates the shared EnvFilter's span state. I discussed that in EnvFilter does not implement Filter #1868 (comment). This would allow a Filter impl for EnvFilter without modifying the Filter trait, but it seems quite gross and makes the API worse.

@hawkw hawkw added kind/feature New feature or request crate/subscriber Related to the `tracing-subscriber` crate labels Feb 22, 2022
hawkw pushed a commit that referenced this issue Mar 8, 2022
Closes #1955

Call those methods in the `Layer` methods for `Filtered` and delegate them
in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a Layer
can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Layer` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 23, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 23, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 23, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
hawkw pushed a commit that referenced this issue Mar 24, 2022
Closes #1955

Call those methods in the `Subscribe` methods for `Filtered` and
delegate them  in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a
subscriber can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Subscribe` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See #1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
@hawkw hawkw closed this as completed in db869b9 Mar 24, 2022
kaffarell pushed a commit to kaffarell/tracing that referenced this issue May 22, 2024
…#1973)

Closes tokio-rs#1955

Call those methods in the `Layer` methods for `Filtered` and delegate them
in the filter combinators

## Motivation

Currently, if a `Filter` is going to implement dynamic filtering, it must
do this by querying the wrapped Subscriber for the current span context.
Since `Filter` only has callsite_enabled and enabled methods, a `Filter`
implementation cannot track the span context internally, the way a Layer
can.

Unfortunately, this means that the current implementation of `EnvFilter`
can only implement `Layer` (and provide global filtering). It cannot
currently implement `Filter`, because it stores span context data
internally. See tokio-rs#1868 for
details.

## Proposal

We should add `on_new_span`, `on_enter`, `on_exit`, and `on_close` methods to
`Filter`. This would allow implementing `Filter`s (such as `EnvFilter`) that
internally track span states.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/subscriber Related to the `tracing-subscriber` crate kind/feature New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant