mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 07:20:35 +00:00
core: allow ValueSet
s of any length (#2508)
## Motivation Fixes: #1566 ## Solution This change removes the maximum of 32 fields limitation using const generics. Having this arbitrary restriction in place to prevent stack overflows feels a little misplaced to me since stack size varies between environments.
This commit is contained in:
parent
df6793f7b7
commit
1771128aea
@ -879,9 +879,6 @@ impl FieldSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a new `ValueSet` with entries for this `FieldSet`'s values.
|
/// Returns a new `ValueSet` with entries for this `FieldSet`'s values.
|
||||||
///
|
|
||||||
/// Note that a `ValueSet` may not be constructed with arrays of over 32
|
|
||||||
/// elements.
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn value_set<'v, V>(&'v self, values: &'v V) -> ValueSet<'v>
|
pub fn value_set<'v, V>(&'v self, values: &'v V) -> ValueSet<'v>
|
||||||
where
|
where
|
||||||
@ -1080,28 +1077,10 @@ impl<'a> fmt::Display for ValueSet<'a> {
|
|||||||
mod private {
|
mod private {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
/// Marker trait implemented by arrays which are of valid length to
|
/// Restrictions on `ValueSet` lengths were removed in #2508 but this type remains for backwards compatibility.
|
||||||
/// construct a `ValueSet`.
|
|
||||||
///
|
|
||||||
/// `ValueSet`s may only be constructed from arrays containing 32 or fewer
|
|
||||||
/// elements, to ensure the array is small enough to always be allocated on the
|
|
||||||
/// stack. This trait is only implemented by arrays of an appropriate length,
|
|
||||||
/// ensuring that the correct size arrays are used at compile-time.
|
|
||||||
pub trait ValidLen<'a>: Borrow<[(&'a Field, Option<&'a (dyn Value + 'a)>)]> {}
|
pub trait ValidLen<'a>: Borrow<[(&'a Field, Option<&'a (dyn Value + 'a)>)]> {}
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! impl_valid_len {
|
impl<'a, const N: usize> ValidLen<'a> for [(&'a Field, Option<&'a (dyn Value + 'a)>); N] {}
|
||||||
( $( $len:tt ),+ ) => {
|
|
||||||
$(
|
|
||||||
impl<'a> private::ValidLen<'a> for
|
|
||||||
[(&'a Field, ::core::option::Option<&'a (dyn Value + 'a)>); $len] {}
|
|
||||||
)+
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_valid_len! {
|
|
||||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
|
|
||||||
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -386,22 +386,6 @@
|
|||||||
//! span.record("parting", &"goodbye world!");
|
//! span.record("parting", &"goodbye world!");
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! Note that a span may have up to 32 fields. The following will not compile:
|
|
||||||
//!
|
|
||||||
//! ```rust,compile_fail
|
|
||||||
//! # use tracing::Level;
|
|
||||||
//! # fn main() {
|
|
||||||
//! let bad_span = span!(
|
|
||||||
//! Level::TRACE,
|
|
||||||
//! "too many fields!",
|
|
||||||
//! a = 1, b = 2, c = 3, d = 4, e = 5, f = 6, g = 7, h = 8, i = 9,
|
|
||||||
//! j = 10, k = 11, l = 12, m = 13, n = 14, o = 15, p = 16, q = 17,
|
|
||||||
//! r = 18, s = 19, t = 20, u = 21, v = 22, w = 23, x = 24, y = 25,
|
|
||||||
//! z = 26, aa = 27, bb = 28, cc = 29, dd = 30, ee = 31, ff = 32, gg = 33
|
|
||||||
//! );
|
|
||||||
//! # }
|
|
||||||
//! ```
|
|
||||||
//!
|
|
||||||
//! Finally, events may also include human-readable messages, in the form of a
|
//! Finally, events may also include human-readable messages, in the form of a
|
||||||
//! [format string][fmt] and (optional) arguments, **after** the event's
|
//! [format string][fmt] and (optional) arguments, **after** the event's
|
||||||
//! key-value fields. If a format string and arguments are provided,
|
//! key-value fields. If a format string and arguments are provided,
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
//! override their default values.
|
//! override their default values.
|
||||||
//! - The span's [verbosity level]
|
//! - The span's [verbosity level]
|
||||||
//! - A string literal providing the span's name.
|
//! - A string literal providing the span's name.
|
||||||
//! - Finally, between zero and 32 arbitrary key/value fields.
|
//! - Finally, zero or more arbitrary key/value fields.
|
||||||
//!
|
//!
|
||||||
//! [`target`]: super::Metadata::target
|
//! [`target`]: super::Metadata::target
|
||||||
//!
|
//!
|
||||||
|
@ -308,6 +308,48 @@ fn span_with_non_rust_symbol() {
|
|||||||
span!(Level::TRACE, "non-rust", "guid:x-request-id" = "abcdef");
|
span!(Level::TRACE, "non-rust", "guid:x-request-id" = "abcdef");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
|
#[test]
|
||||||
|
fn large_span() {
|
||||||
|
span!(
|
||||||
|
Level::TRACE,
|
||||||
|
"spans with more than 32 fields have been supported since #2508",
|
||||||
|
a = 1,
|
||||||
|
b = 2,
|
||||||
|
c = 3,
|
||||||
|
d = 4,
|
||||||
|
e = 5,
|
||||||
|
f = 6,
|
||||||
|
g = 7,
|
||||||
|
h = 8,
|
||||||
|
i = 9,
|
||||||
|
j = 10,
|
||||||
|
k = 11,
|
||||||
|
l = 12,
|
||||||
|
m = 13,
|
||||||
|
n = 14,
|
||||||
|
o = 15,
|
||||||
|
p = 16,
|
||||||
|
q = 17,
|
||||||
|
r = 18,
|
||||||
|
s = 19,
|
||||||
|
t = 20,
|
||||||
|
u = 21,
|
||||||
|
v = 22,
|
||||||
|
w = 23,
|
||||||
|
x = 24,
|
||||||
|
y = 25,
|
||||||
|
z = 26,
|
||||||
|
aa = 27,
|
||||||
|
bb = 28,
|
||||||
|
cc = 29,
|
||||||
|
dd = 30,
|
||||||
|
ee = 31,
|
||||||
|
ff = 32,
|
||||||
|
gg = 33
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)]
|
||||||
#[test]
|
#[test]
|
||||||
fn event() {
|
fn event() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user