#observability #wasm #web-api #web

emit_web

Instrument Web-based applications using emit

2 unstable releases

0.2.0 Feb 24, 2025
0.1.0 Feb 17, 2025

#781 in Debugging

Download history 83/week @ 2025-02-12 124/week @ 2025-02-19 41/week @ 2025-02-26

248 downloads per month

MIT/Apache

15KB
257 lines

emit_web

web

Current docs

Use emit in WebAssembly applications targeting NodeJS and the browser.

Getting started

First, add emit and emit_web to your Cargo.toml:

[dependencies.emit]
version = "1"
# Important: Make sure you set `default-features = false`
default-features = false
features = ["std", "implicit_rt"]

[dependencies.emit_web]
version = "0.2.0"

Ensure you set default-features = false on emit, so it won't try compile dependencies that aren't compatible with WebAssembly.

Next, configure emit to use web APIs in its runtime:

use wasm_bindgen::prelude::*;

#[wasm_bindgen]
pub fn setup() {
    let _ = emit::setup()
        .emit_to(emit_web::console())
        .with_clock(emit_web::date_clock())
        .with_rng(emit_web::crypto_rng())
        .try_init();
}

The name of this function doesn't matter, you'll just need to call it somewhere early in your application. You'll need to at least override the default clock and source of randomness, otherwise you'll get events without timestamps, and spans without ids.

Output

emit_web will output events to the Console API, where they'll appear in browser dev tools.

emit events written to the browser console

Dependencies

~5.5MB
~63K SLoC