Crates.io | emit_web |
lib.rs | emit_web |
version | |
source | src |
created_at | 2025-02-17 21:06:07.256924+00 |
updated_at | 2025-02-24 21:07:52.760304+00 |
description | Instrument Web-based applications using emit. |
homepage | |
repository | https://github.com/emit-rs/emit_web |
max_upload_size | |
id | 1559349 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
emit_web
Use emit
in WebAssembly applications targeting NodeJS and the browser.
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.
emit_web
will output events to the Console API, where they'll appear in browser dev tools.