-
Notifications
You must be signed in to change notification settings - Fork 11
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
Allow customizing logged span events #40
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
fn value_variants<'a>() -> &'a [Self] { | ||
&[ | ||
Self(FmtSpan::NEW), | ||
Self(FmtSpan::ENTER), | ||
Self(FmtSpan::EXIT), | ||
Self(FmtSpan::CLOSE), | ||
Self(FmtSpan::NONE), | ||
Self(FmtSpan::ACTIVE), | ||
Self(FmtSpan::FULL), | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
I'm surprised this lifetime can't be elided?
-
Could this list be generated with the Rust equivalent of
[minBound .. maxBound]
in Haskell? The compiler won't tell you if a new variant is added, making this list incomplete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Me too! I guess the trait definition has an explicit lifetime so you're not allowed to elide it here?
Compilation error when I elide the lifetime
error[E0106]: missing lifetime specifier
--> src/clap/fmt_span.rs:20:28
|
20 | fn value_variants() -> &[Self] {
| ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime
|
20 | fn value_variants() -> &'static [Self] {
| +++++++
error[E0195]: lifetime parameters or bounds on method `value_variants` do not match the trait declaration
--> src/clap/fmt_span.rs:20:22
|
20 | fn value_variants() -> &[Self] {
| ^ lifetimes do not match method in trait
Some errors have detailed explanations: E0106, E0195.
For more information about an error, try `rustc --explain E0106`.
- I wish! This has been an open issue since before Rust 1.0 (peep the Ruby-like syntax in the original issue here). There's a few crates that implement this functionality for
enum
types with#[derive]
macros, but they're pretty heavy so we don't use them here.
fn to_possible_value(&self) -> Option<PossibleValue> { | ||
Some(match self.0 { | ||
FmtSpan::NEW => PossibleValue::new("new").help("Log when spans are created"), | ||
FmtSpan::ENTER => PossibleValue::new("enter").help("Log when spans are entered"), | ||
FmtSpan::EXIT => PossibleValue::new("exit").help("Log when spans are exited"), | ||
FmtSpan::CLOSE => PossibleValue::new("close").help("Log when spans are dropped"), | ||
FmtSpan::NONE => PossibleValue::new("none").help("Do not log span events"), | ||
FmtSpan::ACTIVE => { | ||
PossibleValue::new("active").help("Log when spans are entered/exited") | ||
} | ||
FmtSpan::FULL => PossibleValue::new("full").help("Log all span events"), | ||
_ => { | ||
return None; | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this one of those permanently non-exhaustive enum things, or are you ignoring some of the options? If the latter, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The former. The FmtSpan
type is actually defined as a wrapper around a u8
, not an enum
:
pub struct FmtSpan(u8);
impl FmtSpan {
pub const NEW: FmtSpan = FmtSpan(1 << 0);
// ...
}
https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/format/struct.FmtSpan.html
So these look like enum
variants, but they're actually constants in the type's namespace. (You can tell something funky is up because they're written in ALL_CAPS
rather than TitleCase
.)
In short: this is necessary to make the compiler not complain.
488220b
to
d7c407c
Compare
Currently, new/close span events are logged (that is, when a span is created for the first time, usually when an `#[instrument]`ed function is called, and when spans are closed, usually when those functions return). It can be useful to disable those for terser logs, or to enable more events for greater detail. This change adds a `--trace-spans` argument to customize which span events are logged. Before shipping 1.0, we should clean up the option names. Maybe `--tracing-filter` could be `--log` or something.
Currently, new/close span events are logged (that is, when a span is created for the first time, usually when an
#[instrument]
ed function is called, and when spans are closed, usually when those functions return). It can be useful to disable those for terser logs, or to enable more events for greater detail.This change adds a
--trace-spans
argument to customize which span events are logged.Before shipping 1.0, we should clean up the option names. Maybe
--tracing-filter
could be--log
or something.