Crate emit_web

Crate emit_web 

Source
Expand description

emit_web

Use emit in WebAssembly applications targeting NodeJS and the browser.

emit itself and some emitters, like emit_otlp support WebAssembly directly. This library includes support for emitting events to the Console API. It also has alternative clocks and randomness using different web features. These aren’t required for configuration, but can be used to more directly control the JavaScript APIs emit makes use of.

§Getting started

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

[dependencies.emit]
version = "1"

[dependencies.emit_web]
version = "0.2.1"

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())
        .try_init();
}

The name of this setup function doesn’t matter, you’ll just need to call it somewhere early in your application.

Structs§

ConsoleEmitter
An emitter based on the Console API.
CryptoRng
An RNG based on the Crypto API.
DateClock
A clock based on the Date type.
PerformanceClock
A clock based on the Performance API.

Functions§

console
An emitter based on the Console API.
crypto_rng
A source of randomness based on the Crypto API.
date_clock
A clock based on the Date type.
performance_clock
A clock based on the Performance API.