Skip to main content

Crate wide_event

Crate wide_event 

Source
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

  1. WideEvent::new starts a timer and creates an empty field map.
  2. Throughout processing, call setters (set_str, set_u64, incr, etc.) to accumulate fields — these are cheap local Mutex operations that never touch the tracing subscriber.
  3. WideEvent::emit (or WideEventGuard drop) finalizes the record, pushes it to a thread-local stack, and dispatches a structured tracing::info! event. The WideEventLayer pulls the record from the stack, formats the timestamp using the configured FormatTime implementation, 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 — 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.

Structs§

JsonFormatter
Formats wide events as single-line JSON objects.
LogfmtFormatter
Formats wide events as logfmt (key=value pairs).
Rfc3339
Default timer: RFC 3339 timestamps with microsecond precision.
WideEvent
A wide event that accumulates structured fields over its lifetime.
WideEventGuard
RAII guard that emits the wide event when dropped.
WideEventLayer
A tracing_subscriber::Layer that writes wide event output.
WideEventRecord
A finalized wide event record ready for formatting.

Constants§

DEFAULT_TARGET
Default target used for wide event tracing dispatches.

Traits§

FormatTime
A type that can measure and format the current time.
WideEventFormatter
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§

EmitHook
Callback invoked just before serialization with the accumulated fields.