Expand description
§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 wide_event::{WideEventGuard, WideEventLayer};
use tracing_subscriber::prelude::*;
// Once at startup:
tracing_subscriber::registry()
.with(WideEventLayer::stdout().with_system("myapp"))
.init();
// Per request — guard auto-emits on drop:
{
let req = WideEventGuard::new("http");
req.set_str("method", "GET");
req.set_str("path", "/api/users");
req.set_u64("status", 200);
} // ← 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 using the configuredFormatTimeimplementation, and serializes in a single pass.
§Timestamp control
Timestamps are formatted by a FormatTime implementation configured
on the layer. The default is Rfc3339 (e.g. 2024-01-15T14:30:00.123Z).
Swap it for any tracing_subscriber::fmt::time implementation:
use wide_event::WideEventLayer;
use tracing_subscriber::fmt::time::Uptime;
tracing_subscriber::registry()
.with(WideEventLayer::stdout().with_timer(Uptime::default()))
.init();§Features
opentelemetry— attachestrace_idandspan_idfrom the current OpenTelemetry span context.tokio— provides [context::scope] and [context::current] for async task-local wide event propagation.
Structs§
- Json
Formatter - Formats wide events as single-line JSON objects.
- Logfmt
Formatter - Formats wide events as logfmt (
key=valuepairs). - Rfc3339
- Default timer: RFC 3339 timestamps with microsecond precision.
- Wide
Event - A wide event that accumulates structured fields over its lifetime.
- Wide
Event Guard - RAII guard that emits the wide event when dropped.
- Wide
Event Layer - A
tracing_subscriber::Layerthat writes wide event output. - Wide
Event Record - A finalized wide event record ready for formatting.
Constants§
- DEFAULT_
TARGET - Default target used for wide event tracing dispatches.
Traits§
- Format
Time - A type that can measure and format the current time.
- Wide
Event Formatter - Trait for formatting a wide event record into a writer.
Functions§
- exclude_
wide_ events - Filter function that excludes wide events from other layers.
Type Aliases§
- Emit
Hook - Callback invoked just before serialization with the accumulated fields.