core: impl field::Value for Option<T>#1585
Conversation
|
Ah yeah, I also rebased it onto |
67c1246 to
001b384
Compare
|
Ugh...the CI failure isn't your fault, it looks like a recent release of a dependency ( |
OK, I won't worry about that one. (The force push was to fix a legitimate style test failure.) |
|
Actually, now that I think about it, does it make more sense to PR this against the I'm guessing If that makes sense, I'll rebase tomorrow morning. |
hyperium/http#481, includes context on (deliberate) MSRV bump |
Add tests for making an `Option<T> where T: Value` a value in itself.
001b384 to
d8e87d0
Compare
|
Rebased to PR off of |
hawkw
left a comment
There was a problem hiding this comment.
Thanks, this looks good to me overall!
Rebased to PR off of
v0.1.xbecause this change seems appropriate to get into the 0.1.x line, but may be completely unnecessary in the 0.2.x line if 0.2.x comes with full Valuable support.
Yes, I think basing this on v0.1.x seems correct; the valuable support on 0.2 will make this unnecessary (and may, in fact, result in a conflicting impl, since I believe Options already have Valuable impls in valuable).
Based on this comment #1393 (review) by @hawkw it looks like the only thing holding up #1393 is some tests? If so, here is one test. Let me know what other tests you'd like to see and I'll get them added.
Yeah, the tests were kind of a blocker because I thought it was important that code with expected uses of this API actually compiles and works as expected. :) I think we probably also want to add tests for references to Options, for that reason.
A couple other things that would be nice to do, but can be done in follow-up branches:
- it's probably worth adding examples of recording
Optionvalues in the docs, maybe in this section?Line 242 in e455367
- Also, we'll want to add support for
Optionvalues in theinstrumentattribute, somewhere around here:That way, a function withtracing/tracing-attributes/src/lib.rs
Lines 1091 to 1142 in e455367
#[instrument]can record anyOptionarguments as typedOptionvalues when the value inside the option implementsValue.
But, those can both be done in subsequent changes, so we can get this merged and move forward!
This adds tests for references to options, and adds `.only()` to the expected fields in the tests.
hawkw
left a comment
There was a problem hiding this comment.
i went ahead and applied my test suggestions, and once CI passes, we can merge this, and make the follow-up changes in other branches!
hahaha lol never edit code in the github webapp suggestions UI. i have some regrets.
# 0.1.21 (October 1, 2021) This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) ### Fixed - Fixed deprecation warnings when building with `default-features` disabled ([#1603], [#1606]) - Documentation fixes and improvements ([#1595], [#1601]) Thanks to @BrianBurgers, @DCjanus, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1595 [#1601]: #1601 [#1603]: #1603 [#1606]: #1606
# 0.1.21 (October 1, 2021) This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) ### Fixed - Fixed deprecation warnings when building with `default-features` disabled ([#1603], [#1606]) - Documentation fixes and improvements ([#1595], [#1601]) Thanks to @BrianBurgers, @DCjanus, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1595 [#1601]: #1601 [#1603]: #1603 [#1606]: #1606
|
Would it make sense to use |
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([#1600], [#1605], [#1614], [#1616], [#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([#1602]) - Documentation fixes and improvements ([#1595], [#1601], [#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [#1585]: #1585 [#1595]: #1596 [#1597]: #1597 [#1600]: #1600 [#1601]: #1601 [#1602]: #1602 [#1605]: #1605 [#1614]: #1614 [#1616]: #1616 [#1617]: #1617
## Motivation
Building a span with some field might be `None` is bother now.
Before:
```rust
let span = info!("example", data = Empty );
if let Some(data) = foo() {
span.record("data", &data);
}
```
After:
```rust
let span = info!("example", data = foo() );
```
Co-authored-by: DCjanus <DCjanus@dcjanus.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
# 0.1.21 (October 1, 2021) This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([tokio-rs#1585]) ### Fixed - Fixed deprecation warnings when building with `default-features` disabled ([tokio-rs#1603], [tokio-rs#1606]) - Documentation fixes and improvements ([tokio-rs#1595], [tokio-rs#1601]) Thanks to @BrianBurgers, @DCjanus, and @matklad for contributing to this release! [tokio-rs#1585]: tokio-rs#1585 [tokio-rs#1595]: tokio-rs#1595 [tokio-rs#1601]: tokio-rs#1601 [tokio-rs#1603]: tokio-rs#1603 [tokio-rs#1606]: tokio-rs#1606
# 0.1.29 (October 5th, 2021 This release adds support for recording `Option<T> where T: Value` as typed `tracing` field values. It also includes significant performance improvements for functions annotated with the `#[instrument]` attribute when the generated span is disabled. ### Changed - `tracing-core`: updated to v0.1.21 - `tracing-attributes`: updated to v0.1.19 ### Added - **field**: `Value` impl for `Option<T> where T: Value` ([tokio-rs#1585]) - **attributes**: - improved performance when skipping `#[instrument]`-generated spans below the max level ([tokio-rs#1600], [tokio-rs#1605], [tokio-rs#1614], [tokio-rs#1616], [tokio-rs#1617]) ### Fixed - **instrument**: added missing `Future` implementation for `WithSubscriber`, making the `WithDispatch` extension trait actually useable ([tokio-rs#1602]) - Documentation fixes and improvements ([tokio-rs#1595], [tokio-rs#1601], [tokio-rs#1597]) Thanks to @BrianBurgers, @mattiast, @DCjanus, @oli-obk, and @matklad for contributing to this release! [tokio-rs#1585]: tokio-rs#1585 [tokio-rs#1595]: tokio-rs#1596 [tokio-rs#1597]: tokio-rs#1597 [tokio-rs#1600]: tokio-rs#1600 [tokio-rs#1601]: tokio-rs#1601 [tokio-rs#1602]: tokio-rs#1602 [tokio-rs#1605]: tokio-rs#1605 [tokio-rs#1614]: tokio-rs#1614 [tokio-rs#1616]: tokio-rs#1616 [tokio-rs#1617]: tokio-rs#1617
I'm very interested in #1393 getting merged. Yep, I'm aware that the
Valuablework may supersede this, but in the mean time this would be a huge improvement for how we use tracing.Based on this comment #1393 (review) by @hawkw it looks like the only thing holding up #1393 is some tests? If so, here is one test. Let me know what other tests you'd like to see and I'll get them added.
I wasn't quite sure how to assert that the mock did not record fields
none_str,none_bool, etc.