Struct Metadata
pub struct Metadata<'a> { /* private fields */ }
Expand description
Metadata describing a span or event.
All spans and events have the following metadata:
- A name, represented as a static string.
- A target, a string that categorizes part of the system where the span
or event occurred. The
tracing
macros default to using the module path where the span or event originated as the target, but it may be overridden. - A verbosity level. This determines how verbose a given span or event
is, and allows enabling or disabling more verbose diagnostics
situationally. See the documentation for the
Level
type for details. - The names of the fields defined by the span or event.
- Whether the metadata corresponds to a span or event.
In addition, the following optional metadata describing the source code location where the span or event originated may be provided:
- The file name
- The line number
- The module path
Metadata is used by Subscriber
s when filtering spans and events, and it
may also be used as part of their data payload.
When created by the event!
or span!
macro, the metadata describing a
particular event or span is constructed statically and exists as a single
static instance. Thus, the overhead of creating the metadata is
significantly lower than that of creating the actual span. Therefore,
filtering is based on metadata, rather than on the constructed span.
§Equality
In well-behaved applications, two Metadata
with equal
callsite identifiers will be equal in all other ways (i.e., have the same
name
, target
, etc.). Consequently, in release builds, Metadata::eq
only checks that its arguments have equal callsites. However, the equality
of Metadata
’s other fields is checked in debug builds.
Implementations§
§impl<'a> Metadata<'a>
impl<'a> Metadata<'a>
pub const fn new(
name: &'static str,
target: &'a str,
level: Level,
file: Option<&'a str>,
line: Option<u32>,
module_path: Option<&'a str>,
fields: FieldSet,
kind: Kind,
) -> Metadata<'a>
Available on crate feature cpu_os_threads
only.
pub const fn new( name: &'static str, target: &'a str, level: Level, file: Option<&'a str>, line: Option<u32>, module_path: Option<&'a str>, fields: FieldSet, kind: Kind, ) -> Metadata<'a>
cpu_os_threads
only.Construct new metadata for a span or event, with a name, target, level, field names, and optional source code location.
pub fn fields(&self) -> &FieldSet
Available on crate feature cpu_os_threads
only.
pub fn fields(&self) -> &FieldSet
cpu_os_threads
only.Returns the names of the fields on the described span or event.
pub fn level(&self) -> &Level
Available on crate feature cpu_os_threads
only.
pub fn level(&self) -> &Level
cpu_os_threads
only.Returns the level of verbosity of the described span or event.
pub fn name(&self) -> &'static str
Available on crate feature cpu_os_threads
only.
pub fn name(&self) -> &'static str
cpu_os_threads
only.Returns the name of the span.
pub fn target(&self) -> &'a str
Available on crate feature cpu_os_threads
only.
pub fn target(&self) -> &'a str
cpu_os_threads
only.Returns a string describing the part of the system where the span or event that this metadata describes occurred.
Typically, this is the module path, but alternate targets may be set when spans or events are constructed.
pub fn module_path(&self) -> Option<&'a str>
Available on crate feature cpu_os_threads
only.
pub fn module_path(&self) -> Option<&'a str>
cpu_os_threads
only.Returns the path to the Rust module where the span occurred, or
None
if the module path is unknown.
pub fn file(&self) -> Option<&'a str>
Available on crate feature cpu_os_threads
only.
pub fn file(&self) -> Option<&'a str>
cpu_os_threads
only.Returns the name of the source code file where the span
occurred, or None
if the file is unknown
pub fn line(&self) -> Option<u32>
Available on crate feature cpu_os_threads
only.
pub fn line(&self) -> Option<u32>
cpu_os_threads
only.Returns the line number in the source code file where the span
occurred, or None
if the line number is unknown.
pub fn callsite(&self) -> Identifier
Available on crate feature cpu_os_threads
only.
pub fn callsite(&self) -> Identifier
cpu_os_threads
only.Returns an opaque Identifier
that uniquely identifies the callsite
this Metadata
originated from.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Metadata<'a>
impl<'a> !RefUnwindSafe for Metadata<'a>
impl<'a> Send for Metadata<'a>
impl<'a> Sync for Metadata<'a>
impl<'a> Unpin for Metadata<'a>
impl<'a> !UnwindSafe for Metadata<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.