48 releases

new 0.11.5 Jan 12, 2025
0.11.0-alpha.21 Oct 21, 2024
0.11.0-alpha.7 Jul 31, 2024
0.10.0 Jul 4, 2016
0.1.0 Aug 8, 2015

#48 in Debugging

Download history 113/week @ 2024-09-22 146/week @ 2024-09-29 44/week @ 2024-10-06 273/week @ 2024-10-13 279/week @ 2024-10-20 37/week @ 2024-10-27 52/week @ 2024-11-03 2/week @ 2024-11-10 10/week @ 2024-11-17 27/week @ 2024-11-24 98/week @ 2024-12-01 359/week @ 2024-12-08 55/week @ 2024-12-15 16/week @ 2024-12-22 26/week @ 2024-12-29 760/week @ 2025-01-05

868 downloads per month
Used in 8 crates

MIT/Apache

3MB
12K SLoC

Rust 10K SLoC // 0.2% comments JavaScript 2K SLoC // 0.0% comments

emit

all

Developer-first diagnostics for Rust applications

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:

Getting started

Add emit to your Cargo.toml:

[dependencies.emit]
version = "0.11.5"
# Optional
features = ["serde"]

# Optional
[dependencies.emit_term]
version = "0.11.5"

# 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}!");
}

The output of running the above program

Tracing

emit can also produce trace data that's compatible with standard tracing tools, like Zipkin.

An example trace produced by emit in Zipkin

The above screenshot was generated by this example application.

See the guide for details.

Metrics

emit can also produce metric data that's compatible with standard metric tools, like Prometheus.

An example metric produced by emit in Prometheus

The above screenshot was generated by this example application.

See the guide for details.

Quick debugging

emit has a dbg! macro like the standard library's which you can use for quick-and-dirty debugging:

#[derive(Debug)]
pub struct User<'a> {
    id: u32,
    name: &'a str,
}

emit::dbg!(&User { id: 1, name: "Rust" });

See the guide for details.

Dependencies