Expand description
Structured diagnostics for Rust applications.
emit is a framework for adding diagnostics to your Rust applications with a simple, powerful data model and an expressive syntax inspired by Message Templates.
These are the technical API docs for emit. Also see the guide for a complete introduction.
§Getting started
[dependencies.emit]
version = "0.11.4"
[dependencies.emit_term]
version = "0.11.4"fn main() {
let rt = emit::setup()
.emit_to(emit_term::stdout())
.init();
// Your app code goes here
greet("Rust");
rt.blocking_flush(std::time::Duration::from_secs(5));
}
#[emit::span("Greet {user}")]
fn greet(user: &str) {
emit::info!("Hello, {user}!");
}The setup() function configures emit with an Emitter to write Events to. The emit macro emits an event, capturing any ambient state referred to in its template. The span macro instruments a function, timing its execution and correlating any other events emitted within it together.
§Stable vs nightly toolchains
emit works on stable versions of Rust, but can provide more accurate compiler messages on nightly toolchains.
§Crate features
std(default): Enable support for the standard library. Enable capturing properties as errors. Impliesalloc.alloc: Enable APIs that require an allocator.implicit_rt(default): Enable configuring the default shared runtime and callingemitandspanwithout needing to specify a runtime manually.implicit_internal_rt(default): Enable configuring the internal runtime foremit’s own diagnostics.sval: Enable capturing complex properties usingsval.serde: Enable capturing complex properties usingserde.
§Troubleshooting
Emitters write their own diagnostics to an alternative emit runtime, which you can configure via Setup::init_internal to debug them:
fn main() {
// Configure the internal runtime before your regular setup
let internal_rt = emit::setup()
.emit_to(emit_term::stdout())
.init_internal();
let rt = emit::setup()
.emit_to(emit::emitter::from_fn(|evt| println!("{evt:#?}")))
.init();
// Your app code goes here
rt.blocking_flush(std::time::Duration::from_secs(5));
// Flush the internal runtime after your regular setup
internal_rt.blocking_flush(std::time::Duration::from_secs(5));
}Re-exports§
pub use self::frame::Frame;pub use self::kind::Kind;pub use self::level::Level;pub use self::metric::Metric;pub use self::span::Span;pub use self::span::SpanCtxt;pub use self::span::SpanId;pub use self::span::TraceId;pub use self::timer::Timer;pub use setup::setup;pub use setup::Setup;
Modules§
- The
Andtype. - The
Clocktype. - The
Ctxttype. - The
Emittertype. - The
Emptytype. - Utilities for working with the
errwell-known property. - The
Eventtype. - The
Extenttype. - The
Filtertype. - The
Frametype. - The
Kindtype. - The
Leveltype. - The
Metrictype. - The
Ortype. - The
Pathtype. - Components provided by the underlying platform.
- The
Propstype. - The
Rngtype. - The
Runtimetype. - The
Setuptype. - The
Spantype. - The
Strtype. - The
Templatetype. - The
Timertype. - The
Timestamptype. - The
Valuetype. - Extensions to the diagnostic model using well-known properties.
Macros§
- Emit a temporary debug event.
- Emit a debug event.
- Construct a debug event.
- Emit an event.
- Emit an error event.
- Construct an error event.
- Construct an event.
- Format a template.
- Emit an info event.
- Construct an info event.
- Get a
Pathof the executing module for use inEvent::mdl. - Start a debug span.
- Start an error span.
- Start an info span.
- Start a span.
- Start a warning span.
- Construct a path.
- Get a
Pathof the package name for use inEvent::mdl. - Construct a set of properties.
- Construct a template.
- Emit a warn event.
- Construct a warn event.
Structs§
- A type that behaves like a default, empty, null value.
- A captured record of something significant that occurred during the operation of a system.
- A hierarchical identifier, such as
a::b::c. - A string value.
- A lazily evaluated text template with named holes for interpolating properties into.
- A Unix timestamp with nanosecond precision.
- An anonymous captured value that can be serialized or formatted.
Traits§
- A service to get the current
Timestamp. - Storage for ambient
Props. - An asynchronous destination for diagnostic data.
- A filter over
Events. - A non-cryptographic source of randomness.
Functions§
- Flush the runtime, ensuring all diagnostic events are fully processed.
- Get the shared clock.
- Get the shared context.
- Emit an event.
- Get the shared emitter.
- Get the shared filter.
- Get the shared random generator.
Attribute Macros§
- Capture a property using its
Debugimplementation. - Capture a property using its
Displayimplementation. - Capture a property using its
Errorimplementation. - Capture a property using its
serde::Serializeimplementation. - Capture a property using its
sval::Valueimplementation. - Capture a property using its
ToValueimplementation. - Wrap an operation in a debug span.
- Wrap an operation in an error span.
- Specify Rust format flags to use when rendering a property in a template.
- Wrap an operation in an info span.
- Specify the key for a property.
- Specify that a property value of
Noneshould not be captured, instead of being captured asnull. - Wrap an operation in a span.
- Wrap an operation in a warn span.