Struct tracing_capture::CapturedSpan
source · pub struct CapturedSpan<'a> { /* private fields */ }
Expand description
Captured tracing span containing a reference to its [Metadata
], values that the span
was created with, stats, and descendant CapturedEvent
s.
CapturedSpan
s are comparable and are partially ordered according
to the capture order. Spans are considered equal iff both are aliases of the same span;
i.e., equality is reference-based rather than content-based.
Two spans from different Storage
s are not ordered and are always non-equal.
Values recorded with the span can be accessed by indexing or using Self::value()
,
or iterated over using Self::values()
.
§Examples
let span: CapturedSpan = // ...
// Accessing event metadata and fields:
assert_eq!(*span.metadata().level(), Level::INFO);
assert_eq!(span["arg"], 42_u64);
assert!(span.value("other_arg").is_none());
// Filtering unsigned integer values:
let numbers = span.values().filter_map(|(_, val)| val.as_uint());
// Accessing the parent span:
let parent_name = span.parent().unwrap().metadata().name();
assert!(span
.ancestors()
.any(|span| span.metadata().name() == "test"));
// Accessing child spans and events:
assert!(span.children().len() > 0);
let child_messages: Vec<&str> = span
.events()
.filter_map(|event| event.message())
.collect();
let descendant_span =
span.descendants().find(|span| span["input"] == "!").unwrap();
Implementations§
source§impl<'a> CapturedSpan<'a>
impl<'a> CapturedSpan<'a>
sourcepub fn deep_scan_spans(self) -> Scanner<Self, DescendantSpans<'a>>
pub fn deep_scan_spans(self) -> Scanner<Self, DescendantSpans<'a>>
Deeply scans all descendants of this span.
sourcepub fn deep_scan_events(
self
) -> Scanner<Self, impl Iterator<Item = CapturedEvent<'a>> + 'a>
pub fn deep_scan_events( self ) -> Scanner<Self, impl Iterator<Item = CapturedEvent<'a>> + 'a>
Deeply scans all descendant events of this span.
source§impl<'a> CapturedSpan<'a>
impl<'a> CapturedSpan<'a>
sourcepub fn metadata(&self) -> &'static Metadata<'static>
pub fn metadata(&self) -> &'static Metadata<'static>
Provides a reference to the span 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 that the span was created with, or which were recorded later.
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 events(&self) -> CapturedEvents<'a> ⓘ
pub fn events(&self) -> CapturedEvents<'a> ⓘ
Returns events attached to this 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.
sourcepub fn children(&self) -> CapturedSpans<'a> ⓘ
pub fn children(&self) -> CapturedSpans<'a> ⓘ
Iterates over the direct children of this span, in the order of their capture.
sourcepub fn descendants(&self) -> DescendantSpans<'a> ⓘ
pub fn descendants(&self) -> DescendantSpans<'a> ⓘ
Iterates over the descendants of this span.
In the simplest case (spans are not re-entered, span parents are contextual), the iteration order is the span capture order. In the general case, no particular order is guaranteed.
sourcepub fn descendant_events(&self) -> DescendantEvents<'a> ⓘ
pub fn descendant_events(&self) -> DescendantEvents<'a> ⓘ
Iterates over the events of the descendants
of this span. The iteration order is not specified. The returned events do not include
the events directly attached to this span; if you need them to be included,
use something like span.events().chain(span.descendant_events())
.
sourcepub fn follows_from(&self) -> CapturedSpans<'a> ⓘ
pub fn follows_from(&self) -> CapturedSpans<'a> ⓘ
Iterates over the spans this span follows from.
Trait Implementations§
source§impl<'a> Captured<'a> for CapturedSpan<'a>
impl<'a> Captured<'a> for CapturedSpan<'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 CapturedSpan<'a>
impl<'a> Clone for CapturedSpan<'a>
source§fn clone(&self) -> CapturedSpan<'a>
fn clone(&self) -> CapturedSpan<'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 CapturedSpan<'_>
impl Debug for CapturedSpan<'_>
source§impl Index<&str> for CapturedSpan<'_>
impl Index<&str> for CapturedSpan<'_>
source§impl PartialEq for CapturedSpan<'_>
impl PartialEq for CapturedSpan<'_>
source§impl PartialOrd for CapturedSpan<'_>
impl PartialOrd for CapturedSpan<'_>
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<CapturedSpan<'_>> for NamePredicate<P>
impl<P: Predicate<str>> Predicate<CapturedSpan<'_>> for NamePredicate<P>
source§fn eval(&self, variable: &CapturedSpan<'_>) -> bool
fn eval(&self, variable: &CapturedSpan<'_>) -> bool
Predicate
against variable
, returning the resulting
boolean.source§impl<'a> ScanExt<'a> for CapturedSpan<'a>
impl<'a> ScanExt<'a> for CapturedSpan<'a>
Scans for CapturedSpan
are shallow, i.e. include only direct children spans / events.