pub struct Span { /* private fields */ }
Expand description
A handle representing a span, with the capability to enter the span if it exists.
If the span was rejected by the current Subscriber
’s filter, entering the
span will silently do nothing. Thus, the handle can be used in the same
manner regardless of whether or not the trace is currently being collected.
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(meta: &'static Metadata<'static>, values: &ValueSet<'_>) -> Span
pub fn new(meta: &'static Metadata<'static>, values: &ValueSet<'_>) -> Span
Constructs a new Span
with the given metadata and set of
field values.
The new span will be constructed by the currently-active Subscriber
,
with the current span as its parent (if one exists).
After the span is constructed, field values and/or follows_from
annotations may be added to it.
Sourcepub fn new_root(meta: &'static Metadata<'static>, values: &ValueSet<'_>) -> Span
pub fn new_root(meta: &'static Metadata<'static>, values: &ValueSet<'_>) -> Span
Constructs a new Span
as the root of its own trace tree, with the
given metadata and set of field values.
After the span is constructed, field values and/or follows_from
annotations may be added to it.
Sourcepub fn child_of<I>(
parent: I,
meta: &'static Metadata<'static>,
values: &ValueSet<'_>,
) -> Spanwhere
I: AsId,
pub fn child_of<I>(
parent: I,
meta: &'static Metadata<'static>,
values: &ValueSet<'_>,
) -> Spanwhere
I: AsId,
Constructs a new Span
as child of the given parent span, with the
given metadata and set of field values.
After the span is constructed, field values and/or follows_from
annotations may be added to it.
Sourcepub fn new_disabled(meta: &'static Metadata<'static>) -> Span
pub fn new_disabled(meta: &'static Metadata<'static>) -> Span
Constructs a new disabled span.
Sourcepub fn enter<F: FnOnce() -> T, T>(&self, f: F) -> T
pub fn enter<F: FnOnce() -> T, T>(&self, f: F) -> T
Executes the given function in the context of this span.
If this span is enabled, then this function enters the span, invokes
and then exits the span. If the span is disabled, f
will still be
invoked, but in the context of the currently-executing span (if there is
one).
Returns the result of evaluating f
.
Sourcepub fn field<Q>(&self, field: &Q) -> Option<Field>
pub fn field<Q>(&self, field: &Q) -> Option<Field>
Returns a Field
for the field with the
given name
, if one exists,
Sourcepub fn has_field<Q>(&self, field: &Q) -> bool
pub fn has_field<Q>(&self, field: &Q) -> bool
Returns true if this Span
has a field for the given
Field
or field name.
Sourcepub fn record<Q, V>(&self, field: &Q, value: &V) -> &Self
pub fn record<Q, V>(&self, field: &Q, value: &V) -> &Self
Visits that the field described by field
has the value value
.
Sourcepub fn record_all(&self, values: &ValueSet<'_>) -> &Self
pub fn record_all(&self, values: &ValueSet<'_>) -> &Self
Visit all the fields in the span
Sourcepub fn is_disabled(&self) -> bool
pub fn is_disabled(&self) -> bool
Returns true
if this span was disabled by the subscriber and does not
exist.
Sourcepub fn follows_from<I>(&self, from: I) -> &Selfwhere
I: AsId,
pub fn follows_from<I>(&self, from: I) -> &Selfwhere
I: AsId,
Indicates that the span with the given ID has an indirect causal relationship with this span.
This relationship differs somewhat from the parent-child relationship: a span may have any number of prior spans, rather than a single one; and spans are not considered to be executing inside of the spans they follow from. This means that a span may close even if subsequent spans that follow from it are still open, and time spent inside of a subsequent span should not be included in the time its precedents were executing. This is used to model causal relationships such as when a single future spawns several related background tasks, et cetera.
If this span is disabled, or the resulting follows-from relationship would be invalid, this function will do nothing.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Span
impl !RefUnwindSafe for Span
impl Send for Span
impl Sync for Span
impl Unpin for Span
impl !UnwindSafe for Span
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)