Files
tokio/tokio-trace/tokio-trace-core/src/event.rs
T

57 lines
2.0 KiB
Rust
Raw Normal View History

2019-02-19 12:15:01 -08:00
//! Events represent single points in time during the execution of a program.
use {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:
2019-03-07 14:42:08 -08:00
/// - `Event`s exist _within the context of a [span]_. Unlike log lines, they
2019-02-19 12:15:01 -08:00
/// 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.
2019-03-07 14:42:08 -08:00
/// - Like spans, `Event`s have structured key-value data known as _[fields]_,
2019-02-19 12:15:01 -08:00
/// 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 structed.
///
2019-03-07 14:42:08 -08:00
/// [span]: ../span
/// [fields]: ../field
2019-02-19 12:15:01 -08:00
#[derive(Debug)]
pub struct Event<'a> {
fields: &'a field::ValueSet<'a>,
metadata: &'a Metadata<'a>,
}
impl<'a> Event<'a> {
/// Constructs a new `Event` with the specified metadata and set of values,
/// and observes it with the current subscriber.
#[inline]
2019-03-07 15:19:26 -08:00
pub fn dispatch(metadata: &'a Metadata<'a>, fields: &'a field::ValueSet) {
2019-02-19 12:15:01 -08:00
let event = Event { metadata, fields };
2019-03-07 15:19:26 -08:00
::dispatcher::get_default(|current| {
2019-02-19 12:15:01 -08:00
current.event(&event);
});
}
/// Visits all the fields on this `Event` with the specified [visitor].
2019-02-19 12:15:01 -08:00
///
2019-03-07 14:42:08 -08:00
/// [visitor]: ../field/trait.Visit.html
2019-02-19 12:15:01 -08:00
#[inline]
pub fn record(&self, visitor: &mut field::Visit) {
self.fields.record(visitor);
2019-02-19 12:15:01 -08:00
}
2019-03-07 14:42:08 -08:00
/// Returns an iterator over the set of values on this `Event`.
2019-02-19 12:15:01 -08:00
pub fn fields(&self) -> field::Iter {
self.fields.field_set().iter()
}
/// Returns [metadata] describing this `Event`.
///
2019-03-07 14:42:08 -08:00
/// [metadata]: ../metadata/struct.Metadata.html
2019-02-19 12:15:01 -08:00
pub fn metadata(&self) -> &Metadata {
self.metadata
}
}