wide-event
Honeycomb-style wide events for Rust.
A wide event accumulates key-value pairs throughout a request (or task) lifecycle and emits them as a single structured event when the request completes. This gives you one row per request in your log aggregator with every dimension attached — perfect for high-cardinality exploratory analysis.
Quick start
use ;
use *;
// Once at startup:
registry
.with
.init;
// Per request — guard auto-emits on drop:
// ← emitted here as single JSON line
How it works
WideEvent::newstarts a timer and creates an empty field map.- Throughout processing, call setters (
set_str,set_u64,incr, etc.) to accumulate fields — these are cheap localMutexoperations that never touch the tracing subscriber. WideEvent::emit(orWideEventGuarddrop) finalizes the record, pushes it to a thread-local stack, and dispatches a structuredtracing::info!event. TheWideEventLayerpulls the record from the stack, formats the timestamp, and serializes in a single pass.
Features
| Feature | Description |
|---|---|
opentelemetry |
Attaches trace_id and span_id from the current OpenTelemetry span context |
tokio |
Provides context::scope and context::current for async task-local wide event propagation |
[]
= { = "0.1", = ["tokio"] }
Formatter options
JsonFormatter(default) — one JSON object per lineLogfmtFormatter—key=valuepairs per line
use ;
let layer = new;
Performance
- Field keys are
&'static str— zero allocation on every setter call. Field names are almost always string literals, so this is natural and avoids thekey.to_string()overhead entirely. - Field setters (
set_str,set_u64,incr, …) are cheap localMutexoperations — they never interact with the tracing subscriber. - Timestamp formatting reuses a thread-local buffer — no
Stringallocation per emit. - Serialization happens once at emit time in a single pass over the accumulated fields.
- A thread-local emit stack avoids cross-thread synchronization on the hot path.
Development
# Set up pre-push hook (runs fmt, clippy, tests before each push)
# Release a new version (bumps Cargo.toml, commits, tags, pushes)
# CI publishes to crates.io automatically on tag push.
Requires cargo-release:
cargo install cargo-release
License
Licensed under either of
at your option.