-
Notifications
You must be signed in to change notification settings - Fork 731
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
trace: Determine new syntax for uninitialized fields #77
Comments
Personally, I think |
## Motivation A common pattern in `tokio-trace` is to use the value of a local variable as a field on a span or event. Currently, this requires code like: ```rust info!(foo = foo); ``` which is not particularly ergonomic given how commonly this occurs. Struct initializers support a shorthand syntax for fields where the name of the field is the same as a local variable, and `tokio-trace` should as well. ## Solution This branch adds support for syntax like ```rust let foo = ...; info!(foo); ``` and ```rust let foo = Foo { bar: ..., ... }; info!(foo.bar) ``` to the `tokio-trace` span and event macros. This syntax also works with the `Debug` and `Display` field shorthand. The span macros previously used a field name with no value to indicate an uninitialized field. A new issue, #1138, has been opened for finding a replacement syntax for uninitialized fields. Until then, the `tokio-trace` macros will no longer provide a way to create fields without values, although the `-core` API will continue to support this. Closes #1062 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@jonhoo, @carllerche, @davidbarsky, and @LucioFranco, just checking to see if supporting uninitialized fields in |
@hawkw It's not a blocking issue for me. I think it can be added later. |
Same 😄 |
I thought about this a bit more and I think I prefer |
Right now, there is no way to indicate that a span field _currently_ has no value but that a value will be recorded later. Tracing used to support this concept, but when we added local-variable shorthand, it was removed from the macros, as we needed to use the previous syntax for indicating empty fields for local variable shorthand. See #77 for details. This commit side-steps the problem of determining an appropriate _syntax_ for empty fields by adding a special value _type_, called `Empty`. Now, empty values can be indicated like ```rust span!("my_span", foo = 5, bar = tracing::field::Empty); ``` The `Empty` type implements `Value`, but its' `record` method is a no-op that doesn't' call any functions on the visitor. Therefore, when a field is empty, the visitor will not see it. An empty field can then be recorded later using `Subscriber::record` (or the corresponding `Span` method in `tracing`). Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Right now, there is no way to indicate that a span field _currently_ has no value but that a value will be recorded later. Tracing used to support this concept, but when we added local-variable shorthand, it was removed from the macros, as we needed to use the previous syntax for indicating empty fields for local variable shorthand. See #77 for details. This commit side-steps the problem of determining an appropriate _syntax_ for empty fields by adding a special value _type_, called `Empty`. Now, empty values can be indicated like ```rust span!("my_span", foo = 5, bar = tracing::field::Empty); ``` The `Empty` type implements `Value`, but its' `record` method is a no-op that doesn't' call any functions on the visitor. Therefore, when a field is empty, the visitor will not see it. An empty field can then be recorded later using `Subscriber::record` (or the corresponding `Span` method in `tracing`). Closes #77 Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Followup from #1062 and tokio-rs/tokio#1103 (comment).
Prior to #1103, the syntax
field,
was used by thetokio-trace
macros to indicate span fields which have yet to have a value recorded. In order to support shorthand for using local variables as fields, we changed the meaning of this syntax, since local variable shorthand is likely to be a more common use-case (see #1103).This leaves uninitialized fields without an appropriate macro syntax. There have been some suggestions, of which I think the strongest thus far are
let field,
andfield = _,
.let field
nicely mirrors the way let bindings with unset values are created in Rust; it does, however, seem somewhat inconsistent with the existing syntax, since other fields do not begin withlet
. On the other hand,field = _
fits in with the existing field syntax, but @carllerche has pointed out that it uses the assignment syntax to indicate something which is unassigned, which seems confusing.We should try to agree on a new syntax for uninitialized fields, and re-enable support for them in the macros.
The text was updated successfully, but these errors were encountered: