1 unstable release
new 0.1.0 | Feb 17, 2025 |
---|
#801 in Debugging
16KB
257 lines
emit_web
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 = "0.11"
# Important: Make sure you set `default-features = false`
default-features = false
features = ["std", "implicit_rt"]
[dependencies.emit_web]
version = "0.1.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.
Dependencies
~5.5MB
~62K SLoC