-
Notifications
You must be signed in to change notification settings - Fork 827
tracing-subscriber: implement Clone for EnvFilter #2398
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
Closed
gelfand
wants to merge
1
commit into
tokio-rs:master
from
gelfand:tracing-subscriber/env-filter-clone
Closed
tracing-subscriber: implement Clone for EnvFilter #2398
gelfand
wants to merge
1
commit into
tokio-rs:master
from
gelfand:tracing-subscriber/env-filter-clone
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Apr 26, 2024
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Apr 26, 2024
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Aug 13, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Aug 13, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Aug 14, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
jplatte
pushed a commit
that referenced
this pull request
Aug 14, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in #2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: #2360
olivia-fl
added a commit
to olivia-fl/tracing
that referenced
this pull request
Aug 14, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
jplatte
pushed a commit
that referenced
this pull request
Aug 15, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in #2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: #2360
jevolk
pushed a commit
to matrix-construct/tracing
that referenced
this pull request
Aug 30, 2025
This is useful when using `EnvFilter` for multiple identical per-layer filters, as well as with clap and similar libraries that have `Clone` bounds. We generally expect users to be cloning an `EnvFilter` before attaching it to a subscriber, rather than cloning `EnvFilters` that are already attached. Because of this, we reset all the accumulated dynamic state when cloning. This means that some spans and callsites might be missed when an already-attached `EnvFilter` is cloned, but the presence of the dynamic state mean that detaching and attaching `EnvFilter`s to existing subscribers (e.g. with `reload`) already doesn't work very well. This isn't a new class of problem. There was a previous implementation of this in tokio-rs#2398, that shared the dynamic state between all cloned filters behind an `Arc`. I chose not do go for that approach because it causes inconsistencies if the cloned filters are attached to different subscribers. Fixes: tokio-rs#2360
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
As of
clap
v4
, there'sClone
bound, thus making it impossible forEnvFilter
to be aclap
command line argument.Solution
Implement
Clone
forEnvFilter
.