//! Events represent single points in time during the execution of a program. usecrate::parent::Parent; usecrate::span::Id; usecrate::{field, Metadata};
/// `Event`s represent single points in time where something occurred during the /// execution of a program. /// /// An `Event` can be compared to a log record in unstructured logging, but with /// two key differences: /// - `Event`s exist _within the context of a [span]_. Unlike log lines, they /// may be located within the trace tree, allowing visibility into the /// _temporal_ context in which the event occurred, as well as the source /// code location. /// - Like spans, `Event`s have structured key-value data known as _[fields]_, /// which may include textual message. In general, a majority of the data /// associated with an event should be in the event's fields rather than in /// the textual message, as the fields are more structured. /// /// [span]: super::span /// [fields]: super::field #[derive(Debug)] pubstruct Event<'a> {
fields: &'a field::ValueSet<'a>,
metadata: &'static Metadata<'static>,
parent: Parent,
}
impl<'a> Event<'a> { /// Constructs a new `Event` with the specified metadata and set of values, /// and observes it with the current subscriber. pubfn dispatch(metadata: &'static Metadata<'static>, fields: &n style='color:blue'>'a field::ValueSet<'_>) { let event = Event::new(metadata, fields); crate::dispatcher::get_default(|current| {
current.event(&event);
});
}
/// Returns a new `Event` in the current span, with the specified metadata /// and set of values. #[inline] pubfn new(metadata: &'static Metadata<'static>, fields: &le='color:blue'>'a field::ValueSet<'a>) -> Self {
Event {
fields,
metadata,
parent: Parent::Current,
}
}
/// Returns a new `Event` as a child of the specified span, with the /// provided metadata and set of values. #[inline] pubfn new_child_of(
parent: impl Into<Option<Id>>,
metadata: &'static Metadata<'static>,
fields: &'a field::ValueSet<'a>,
) -> Self { let parent = match parent.into() {
Some(p) => Parent::Explicit(p),
None => Parent::Root,
};
Event {
fields,
metadata,
parent,
}
}
/// Constructs a new `Event` with the specified metadata and set of values, /// and observes it with the current subscriber and an explicit parent. pubfn child_of(
parent: impl Into<Option<Id>>,
metadata: &'static Metadata<'static>,
fields: &'a field::ValueSet<'_>,
) { let event = Self::new_child_of(parent, metadata, fields); crate::dispatcher::get_default(|current| {
current.event(&event);
});
}
/// Visits all the fields on this `Event` with the specified [visitor]. /// /// [visitor]: super::field::Visit #[inline] pubfn record(&self, visitor: &mutdyn field::Visit) { self.fields.record(visitor);
}
/// Returns an iterator over the set of values on this `Event`. pubfn fields(&self) -> field::Iter { self.fields.field_set().iter()
}
/// Returns true if the new event should be a root. pubfn is_root(&self) -> bool {
matches!(self.parent, Parent::Root)
}
/// Returns true if the new event's parent should be determined based on the /// current context. /// /// If this is true and the current thread is currently inside a span, then /// that span should be the new event's parent. Otherwise, if the current /// thread is _not_ inside a span, then the new event will be the root of its /// own trace tree. pubfn is_contextual(&self) -> bool {
matches!(self.parent, Parent::Current)
}
/// Returns the new event's explicitly-specified parent, if there is one. /// /// Otherwise (if the new event is a root or is a child of the current span), /// returns `None`. pubfn parent(&self) -> Option<&Id> { matchself.parent {
Parent::Explicit(ref p) => Some(p),
_ => None,
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.20 Sekunden
(vorverarbeitet am 2026-06-18)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.