emit
is a framework for adding structured diagnostics to your Rust applications with a simple, powerful data model and an expressive syntax inspired by Message Templates. emit
's guiding design principle is low ceremony, low cognitive-load.
This readme covers just enough to give you an idea of what emit
is. For a proper treatment, see:
Add emit
to your Cargo.toml
:
[dependencies.emit]
version = "0.11.0-alpha.21"
# Optional
features = ["serde"]
# Optional
[dependencies.emit_term]
version = "0.11.0-alpha.21"
# Optional
[dependencies.serde]
version = "1"
features = ["derive"]
Initialize emit
in your main.rs
and start peppering diagnostics throughout your application:
fn main() {
// Configure `emit` to write events to the console
let rt = emit::setup()
.emit_to(emit_term::stdout())
.init();
// Your app code goes here
greet(&User { id: 1, name: "Rust" });
// Flush any remaining events before `main` returns
rt.blocking_flush(std::time::Duration::from_secs(5));
}
#[derive(serde::Serialize)]
pub struct User<'a> {
id: u32,
name: &'a str,
}
#[emit::span("Greet {user}", #[emit::as_serde] user)]
fn greet(user: &User) {
emit::info!("Hello, {user: user.name}!");
}
emit
can also produce trace data that's compatible with standard tracing tools, like Zipkin.
The above screenshot was generated by this example application.
See the guide for details.
emit
can also produce metric data that's compatible with standard metric tools, like Prometheus.
The above screenshot was generated by this example application.
See the guide for details.