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, serde: add valuable support to the JSON formatter #1862

Merged
merged 4 commits into from
Feb 3, 2022

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Jan 26, 2022

This branch introduces support for valuable in tracing-subscriber's
JSON formatter, and in tracing-serde, using the valuable-serde
bridge.

This allows the fmt::Json subscriber to actually record valuable
values as structured JSON. Here's an example, where a field is first
recorded using fmt::Debug, and then again using field::valuable:

:; RUSTFLAGS="--cfg tracing_unstable" cargo run --example valuable_json | jq
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/valuable_json`
{
  "timestamp": "2022-01-25T21:36:30.729658Z",
  "level": "INFO",
  "fields": {
    "valuable": false,
    "user": "User { name: \"Arwen Undomiel\", age: 3000, address: Address { country: \"Middle Earth\", city: \"Rivendell\", street: \"leafy lane\" } }"
  },
  "target": "valuable_json"
}
{
  "timestamp": "2022-01-25T21:36:30.729720Z",
  "level": "INFO",
  "fields": {
    "valuable": true,
    "user": {
      "name": "Arwen Undomiel",
      "age": 3000,
      "address": {
        "country": "Middle Earth",
        "city": "Rivendell",
        "street": "leafy lane"
      }
    }
  },
  "target": "valuable_json"
}

Note that this is currently not mergeable, as it adds a dependency on
the valuable-serde crate, which is unreleased. Also, I'm not sure if
the feature flagging is quite correct in a couple places.

@hawkw
Copy link
Member Author

hawkw commented Jan 26, 2022

As a side note, this branch also nicely validates that recording Valuable
values from a subscriber is actually possible, which the previous valuable PR
didn't have an example of. I am a bit unsure if it's actually the best thin for
record_value to take &dyn Valuable, rather than just taking a Value. In
practice, basically all that you can do with the Valuable trait object is call
as_value on it, anyway. @carllerche any advice?

@hawkw
Copy link
Member Author

hawkw commented Jan 26, 2022

depends on tokio-rs/valuable#82

@hawkw hawkw marked this pull request as ready for review February 2, 2022 22:38
@hawkw hawkw requested a review from a team as a code owner February 2, 2022 22:38
@hawkw hawkw changed the title [WIP] add valuable support to the JSON formatter subscriber, serde: add valuable support to the JSON formatter Feb 3, 2022
@hawkw hawkw enabled auto-merge (squash) February 3, 2022 18:51
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Copy link
Member

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to maybe flatten the JSON output, but there isn't any API space to do that. Next version of subscriber, I guess.

@hawkw
Copy link
Member Author

hawkw commented Feb 3, 2022

I wanted to maybe flatten the JSON output, but there isn't any API space to do that. Next version of subscriber, I guess.

Sorry, can you explain what you mean by this? this API already exists, and I believe it will flatten fields into the top-level object...this change doesn't affect that.

@hawkw hawkw merged commit bfd6802 into v0.1.x Feb 3, 2022
@hawkw hawkw deleted the eliza/valuable-json branch February 3, 2022 22:27
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.1.3 (February 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate. See [this blog post][post] for
details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

### Added

- **valuable**: Experimental support for serializing user-defined types
  using [`valuable`] and [`valuable-serde`] ([#1862])
- Support for serializing `f64` values ([#1507])

### Fixed

- Fixed incorrect size hint in `SerializeFieldSet` ([#1333])
- A number of documentation fixes

Thanks to @akinnane and @maxburke for contributing to this release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable-serde`]: https://crates.io/crates/valuable-serde
[post]: https://tokio.rs/blog/2021-05-valuable
[#1862]: #1862
[#1507]: #1507
[#1333]: #1333

(I also noticed there was a missing changelog entry for v0.1.2, so I
fixed that while I was here)
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.1.3 (February 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate. See [this blog post][post] for
details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

### Added

- **valuable**: Experimental support for serializing user-defined types
  using [`valuable`] and [`valuable-serde`] ([#1862])
- Support for serializing `f64` values ([#1507])

### Fixed

- Fixed incorrect size hint in `SerializeFieldSet` ([#1333])
- A number of documentation fixes

Thanks to @akinnane and @maxburke for contributing to this release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable-serde`]: https://crates.io/crates/valuable-serde
[post]: https://tokio.rs/blog/2021-05-valuable
[#1862]: #1862
[#1507]: #1507
[#1333]: #1333

(I also noticed there was a missing changelog entry for v0.1.2, so I
fixed that while I was here)
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([#1862], [#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([#1890])
- Minor documentation fixes ([#1902], [#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[#1862]: #1862
[#1901]: #1901
[#1903]: #1903
[#1871]: #1871
[#1890]: #1890
[#1902]: #1902
[#1893]: #1893
hawkw added a commit that referenced this pull request Feb 4, 2022
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([#1862], [#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([#1890])
- Minor documentation fixes ([#1902], [#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[#1862]: #1862
[#1901]: #1901
[#1903]: #1903
[#1871]: #1871
[#1890]: #1890
[#1902]: #1902
[#1893]: #1893
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
…o-rs#1862)

This branch introduces support for `valuable` in `tracing-subscriber`'s
JSON formatter, and in `tracing-serde`, using the `valuable-serde`
bridge.

This allows the `fmt::Json` subscriber to actually record `valuable`
values as structured JSON. Here's an example, where a field is first
recorded using `fmt::Debug`, and then again using `field::valuable`:

```
:; RUSTFLAGS="--cfg tracing_unstable" cargo run --example valuable_json | jq
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/valuable_json`
{
  "timestamp": "2022-01-25T21:36:30.729658Z",
  "level": "INFO",
  "fields": {
    "valuable": false,
    "user": "User { name: \"Arwen Undomiel\", age: 3000, address: Address { country: \"Middle Earth\", city: \"Rivendell\", street: \"leafy lane\" } }"
  },
  "target": "valuable_json"
}
{
  "timestamp": "2022-01-25T21:36:30.729720Z",
  "level": "INFO",
  "fields": {
    "valuable": true,
    "user": {
      "name": "Arwen Undomiel",
      "age": 3000,
      "address": {
        "country": "Middle Earth",
        "city": "Rivendell",
        "street": "leafy lane"
      }
    }
  },
  "target": "valuable_json"
}
```

As a side note, this branch also nicely validates that recording `Valuable`
values from a subscriber is actually possible, which the previous valuable PR
didn't have an example of. 

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.1.3 (February 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate. See [this blog post][post] for
details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

### Added

- **valuable**: Experimental support for serializing user-defined types
  using [`valuable`] and [`valuable-serde`] ([tokio-rs#1862])
- Support for serializing `f64` values ([tokio-rs#1507])

### Fixed

- Fixed incorrect size hint in `SerializeFieldSet` ([tokio-rs#1333])
- A number of documentation fixes

Thanks to @akinnane and @maxburke for contributing to this release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable-serde`]: https://crates.io/crates/valuable-serde
[post]: https://tokio.rs/blog/2021-05-valuable
[tokio-rs#1862]: tokio-rs#1862
[tokio-rs#1507]: tokio-rs#1507
[tokio-rs#1333]: tokio-rs#1333

(I also noticed there was a missing changelog entry for v0.1.2, so I
fixed that while I was here)
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
# 0.3.8 (Feb 4, 2022)

This release adds *experimental* support for recording structured field
values using the [`valuable`] crate to the `format::Json` formatter. In
particular, user-defined types which are recorded using their
[`valuable::Valuable`] implementations will be serialized as JSON
objects, rather than using their `fmt::Debug` representation. See [this
blog post][post] for details on `valuable`.

Note that `valuable` support currently requires `--cfg
tracing_unstable`. See the documentation for details.

Additionally, this release includes a number of other smaller API
improvements.

### Added

- **json**: Experimental support for recording [`valuable`] values as
  structured JSON ([tokio-rs#1862], [tokio-rs#1901])
- **filter**: `Targets::would_enable` method for testing if a `Targets`
  filter would enable a given target ([tokio-rs#1903])
- **fmt**: `map_event_format`, `map_fmt_fields`, and `map_writer`
  methods to `fmt::Layer` and `fmt::SubscriberBuilder` ([tokio-rs#1871])

### Changed

- `tracing-core`: updated to [0.1.22][core-0.1.22]

### Fixed

- Set `smallvec` minimal version to 1.2.0, to fix compilation errors
  with `-Z minimal-versions` ([tokio-rs#1890])
- Minor documentation fixes ([tokio-rs#1902], [tokio-rs#1893])

Thanks to @guswynn, @glts, and @lilyball for contributing to this
release!

[`valuable`]: https://crates.io/crates/valuable
[`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
[post]: https://tokio.rs/blog/2021-05-valuable
[core-0.1.22]: https://github.com/tokio-rs/tracing/releases/tag/tracing-core-0.1.22
[tokio-rs#1862]: tokio-rs#1862
[tokio-rs#1901]: tokio-rs#1901
[tokio-rs#1903]: tokio-rs#1903
[tokio-rs#1871]: tokio-rs#1871
[tokio-rs#1890]: tokio-rs#1890
[tokio-rs#1902]: tokio-rs#1902
[tokio-rs#1893]: tokio-rs#1893
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants