Struct tracing_capture::CapturedEvent
source · pub struct CapturedEvent<'a> { /* private fields */ }
Expand description
Captured tracing event containing a reference to its [Metadata
] and values that the event
was created with.
CapturedEvent
s are comparable and are partially ordered according
to the capture order. Events are considered equal iff both are aliases of the same event;
i.e., equality is reference-based rather than content-based.
Two events from different Storage
s are not ordered and are always non-equal.
Values recorded with the event can be accessed by indexing or using Self::value()
,
or iterated over using Self::values()
.
§Examples
let event: CapturedEvent = // ...
// Accessing event metadata and fields:
assert_eq!(*event.metadata().level(), Level::INFO);
assert_eq!(event["return"], 42_u64);
assert_eq!(event.message(), Some("finished computations"));
assert!(event.value("err").is_none());
// Filtering unsigned integer values:
let numbers = event.values().filter_map(|(_, val)| val.as_uint());
// Accessing the parent span:
let parent_name = event.parent().unwrap().metadata().name();
assert!(event
.ancestors()
.any(|span| span.metadata().name() == "test"));
Implementations§
source§impl<'a> CapturedEvent<'a>
impl<'a> CapturedEvent<'a>
sourcepub fn metadata(&self) -> &'static Metadata<'static>
pub fn metadata(&self) -> &'static Metadata<'static>
Provides a reference to the event metadata.
sourcepub fn values(&self) -> impl Iterator<Item = (&'a str, &'a TracedValue)> + 'a
pub fn values(&self) -> impl Iterator<Item = (&'a str, &'a TracedValue)> + 'a
Iterates over values associated with the event.
sourcepub fn value(&self, name: &str) -> Option<&'a TracedValue>
pub fn value(&self, name: &str) -> Option<&'a TracedValue>
Returns a value for the specified field, or None
if the value is not defined.
sourcepub fn message(&self) -> Option<&'a str>
pub fn message(&self) -> Option<&'a str>
Returns the message recorded in this event, i.e., the value of the message
field
if it has a string presentation.
sourcepub fn parent(&self) -> Option<CapturedSpan<'a>>
pub fn parent(&self) -> Option<CapturedSpan<'a>>
Returns the parent span for this event, or None
if is not tied to a captured span.
sourcepub fn ancestors(&self) -> impl Iterator<Item = CapturedSpan<'a>> + '_
pub fn ancestors(&self) -> impl Iterator<Item = CapturedSpan<'a>> + '_
Returns the references to the ancestor spans, starting from the direct parent and ending in one of root spans.
Trait Implementations§
source§impl<'a> Captured<'a> for CapturedEvent<'a>
impl<'a> Captured<'a> for CapturedEvent<'a>
source§fn metadata(&self) -> &'static Metadata<'static>
fn metadata(&self) -> &'static Metadata<'static>
source§fn value(&self, name: &str) -> Option<&'a TracedValue>
fn value(&self, name: &str) -> Option<&'a TracedValue>
None
if the value is not defined.source§fn parent(&self) -> Option<CapturedSpan<'a>>
fn parent(&self) -> Option<CapturedSpan<'a>>
source§impl<'a> Clone for CapturedEvent<'a>
impl<'a> Clone for CapturedEvent<'a>
source§fn clone(&self) -> CapturedEvent<'a>
fn clone(&self) -> CapturedEvent<'a>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for CapturedEvent<'_>
impl Debug for CapturedEvent<'_>
source§impl Index<&str> for CapturedEvent<'_>
impl Index<&str> for CapturedEvent<'_>
source§impl PartialEq for CapturedEvent<'_>
impl PartialEq for CapturedEvent<'_>
source§impl PartialOrd for CapturedEvent<'_>
impl PartialOrd for CapturedEvent<'_>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl<P: Predicate<str>> Predicate<CapturedEvent<'_>> for MessagePredicate<P>
impl<P: Predicate<str>> Predicate<CapturedEvent<'_>> for MessagePredicate<P>
source§fn eval(&self, variable: &CapturedEvent<'_>) -> bool
fn eval(&self, variable: &CapturedEvent<'_>) -> bool
Predicate
against variable
, returning the resulting
boolean.