Skip to content

Commit 31df8cd

Browse files
authored
docs: document tracing-subscriber valuable support (#1901)
This PR adds documentation on `valuable` support in `tracing-serde` and `tracing-subscriber`.
1 parent df4ba17 commit 31df8cd

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

tracing-serde/src/lib.rs

+33
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,36 @@
109109
//! subscriber (`JsonSubscriber` in the above example) to record serialized
110110
//! trace data.
111111
//!
112+
//! ### Unstable Features
113+
//!
114+
//! These feature flags enable **unstable** features. The public API may break in 0.1.x
115+
//! releases. To enable these features, the `--cfg tracing_unstable` must be passed to
116+
//! `rustc` when compiling.
117+
//!
118+
//! The following unstable feature flags are currently available:
119+
//!
120+
//! * `valuable`: Enables [`Visit::record_value`] implementations, for
121+
//! serializing values recorded using the [`valuable`] crate.
122+
//!
123+
//! #### Enabling Unstable Features
124+
//!
125+
//! The easiest way to set the `tracing_unstable` cfg is to use the `RUSTFLAGS`
126+
//! env variable when running `cargo` commands:
127+
//!
128+
//! ```shell
129+
//! RUSTFLAGS="--cfg tracing_unstable" cargo build
130+
//! ```
131+
//! Alternatively, the following can be added to the `.cargo/config` file in a
132+
//! project to automatically enable the cfg flag for that project:
133+
//!
134+
//! ```toml
135+
//! [build]
136+
//! rustflags = ["--cfg", "tracing_unstable"]
137+
//! ```
138+
//!
139+
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
140+
//! [`valuable`]: https://crates.io/crates/valuable
141+
//!
112142
//! ## Supported Rust Versions
113143
//!
114144
//! Tracing is built against the latest stable release. The minimum supported
@@ -130,6 +160,7 @@
130160
html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
131161
issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/"
132162
)]
163+
#![cfg_attr(docsrs, feature(doc_cfg))]
133164
#![cfg_attr(docsrs, deny(rustdoc::broken_intra_doc_links))]
134165
#![warn(
135166
missing_debug_implementations,
@@ -357,6 +388,7 @@ where
357388
S: SerializeMap,
358389
{
359390
#[cfg(all(tracing_unstable, feature = "valuable"))]
391+
#[cfg_attr(docsrs, doc(cfg(all(tracing_unstable, feature = "valuable"))))]
360392
fn record_value(&mut self, field: &Field, value: valuable_crate::Value<'_>) {
361393
if self.state.is_ok() {
362394
self.state = self
@@ -418,6 +450,7 @@ where
418450
S: SerializeStruct,
419451
{
420452
#[cfg(all(tracing_unstable, feature = "valuable"))]
453+
#[cfg_attr(docsrs, doc(cfg(all(tracing_unstable, feature = "valuable"))))]
421454
fn record_value(&mut self, field: &Field, value: valuable_crate::Value<'_>) {
422455
if self.state.is_ok() {
423456
self.state = self

tracing-subscriber/src/fmt/format/json.rs

+14
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,23 @@ use tracing_log::NormalizeEvent;
5252
/// By default, event fields are not flattened, and both current span and span
5353
/// list are logged.
5454
///
55+
/// # Valuable Support
56+
///
57+
/// Experimental support is available for using the [`valuable`] crate to record
58+
/// user-defined values as structured JSON. When the ["valuable" unstable
59+
/// feature][unstable] is enabled, types implementing [`valuable::Valuable`] will
60+
/// be recorded as structured JSON, rather than
61+
/// using their [`std::fmt::Debug`] implementations.
62+
///
63+
/// **Note**: This is an experimental feature. [Unstable features][unstable]
64+
/// must be enabled in order to use `valuable` support.
65+
///
5566
/// [`Json::flatten_event`]: #method.flatten_event
5667
/// [`Json::with_current_span`]: #method.with_current_span
5768
/// [`Json::with_span_list`]: #method.with_span_list
69+
/// [`valuable`]: https://crates.io/crates/valuable
70+
/// [unstable]: crate#unstable-features
71+
/// [`valuable::Valuable`]: https://docs.rs/valuable/latest/valuable/trait.Valuable.html
5872
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
5973
pub struct Json {
6074
pub(crate) flatten_event: bool,

tracing-subscriber/src/lib.rs

+31
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,37 @@
102102
//! tracing-subscriber = { version = "0.3", default-features = false, features = ["alloc"] }
103103
//! ```
104104
//!
105+
//! ### Unstable Features
106+
//!
107+
//! These feature flags enable **unstable** features. The public API may break in 0.1.x
108+
//! releases. To enable these features, the `--cfg tracing_unstable` must be passed to
109+
//! `rustc` when compiling.
110+
//!
111+
//! The following unstable feature flags are currently available:
112+
//!
113+
//! * `valuable`: Enables support for serializing values recorded using the
114+
//! [`valuable`] crate as structured JSON in the [`format::Json`] formatter.
115+
//!
116+
//! #### Enabling Unstable Features
117+
//!
118+
//! The easiest way to set the `tracing_unstable` cfg is to use the `RUSTFLAGS`
119+
//! env variable when running `cargo` commands:
120+
//!
121+
//! ```shell
122+
//! RUSTFLAGS="--cfg tracing_unstable" cargo build
123+
//! ```
124+
//! Alternatively, the following can be added to the `.cargo/config` file in a
125+
//! project to automatically enable the cfg flag for that project:
126+
//!
127+
//! ```toml
128+
//! [build]
129+
//! rustflags = ["--cfg", "tracing_unstable"]
130+
//! ```
131+
//!
132+
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
133+
//! [`valuable`]: https://crates.io/crates/valuable
134+
//! [`format::Json`]: crate::fmt::format::Json
135+
//!
105136
//! ## Supported Rust Versions
106137
//!
107138
//! Tracing is built against the latest stable release. The minimum supported

0 commit comments

Comments
 (0)