Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ impl FieldSet {
/// [`Identifier`]: super::callsite::Identifier
/// [`Callsite`]: super::callsite::Callsite
#[inline]
pub(crate) fn callsite(&self) -> callsite::Identifier {
pub(crate) const fn callsite(&self) -> callsite::Identifier {
callsite::Identifier(self.callsite.0)
}

Expand Down Expand Up @@ -949,6 +949,16 @@ impl FieldSet {
}
}

pub(crate) const fn fake_field(&self) -> Field {
Field {
i: usize::MAX,
fields: FieldSet {
names: self.names,
callsite: self.callsite(),
},
}
}

/// Returns the number of fields in this `FieldSet`.
#[inline]
pub fn len(&self) -> usize {
Expand Down
8 changes: 8 additions & 0 deletions tracing-core/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ impl<'a> Metadata<'a> {
pub fn is_span(&self) -> bool {
self.kind.is_span()
}

/// Generate a fake field that will never match a real field.
///
/// Used via valueset to fill in for unknown fields.
#[doc(hidden)]
pub const fn private_fake_field(&self) -> field::Field {
self.fields.fake_field()
}
}

impl fmt::Debug for Metadata<'_> {
Expand Down
12 changes: 12 additions & 0 deletions tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,18 @@ pub mod __macro_support {
.finish()
}
}

static CALLSITE: crate::callsite::DefaultCallsite =
crate::callsite::DefaultCallsite::new(&META);
static META: crate::Metadata<'static> = crate::metadata! {
name: "__fake_tracing_callsite",
target: module_path!(),
level: crate::Level::TRACE,
fields: crate::fieldset!(),
callsite: &CALLSITE,
kind: crate::metadata::Kind::SPAN,
};
pub static FAKE_FIELD: crate::field::Field = META.private_fake_field();
}

#[cfg(feature = "log")]
Expand Down
Loading
Loading