Expand description
In-memory flight recorder for tracing events.
Inspired by Go 1.25’s trace.FlightRecorder, this crate provides a
tracing_subscriber::Layer that continuously buffers tracing events in a
bounded ring buffer. When something goes wrong — a sync failure, a circuit
breaker opening, a panic — you snapshot the buffer and get the last N
seconds of verbose (DEBUG/TRACE) context that would otherwise be lost.
Events capture their full span hierarchy (names + fields), so snapshots
preserve request context like request_id, user_id, and method.
Sensitive fields are automatically redacted in both events and spans.
The recorder pays zero I/O cost until a snapshot is triggered.
§Quick Start
use tracing_flight_recorder::{FlightRecorder, FlightRecorderLayer};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use tracing_subscriber::Layer;
let recorder = FlightRecorder::new(1000);
// CRITICAL: apply per-layer filtering so the recorder sees DEBUG+
// while the console stays at INFO. A global EnvFilter would block
// DEBUG/TRACE events from reaching the recorder layer entirely.
let fr_filter = tracing_subscriber::EnvFilter::new("my_app=debug,warn");
let console_filter = tracing_subscriber::EnvFilter::new("info");
tracing_subscriber::registry()
.with(FlightRecorderLayer::new(recorder.clone()).with_filter(fr_filter))
.with(tracing_subscriber::fmt::layer().with_filter(console_filter))
.init();
// ... application code ...
// On error: dump the last 1000 events to disk
recorder.dump_to_file(std::path::Path::new("flight-recorder.json")).ok();§Minimal Example
use tracing_flight_recorder::FlightRecorder;
let recorder = FlightRecorder::new(50);
assert!(recorder.is_empty());
assert_eq!(recorder.capacity(), 50);Structs§
- Captured
Event - A single tracing event captured into a serializable form.
- Dump
Event - Payload delivered to an
on_dumpcallback after a snapshot is attempted. - Flight
Recorder - A bounded in-memory ring buffer of tracing events.
- Flight
Recorder Dump - A complete flight-recorder dump: diagnostic metadata + the captured events.
- Flight
Recorder Layer - A
tracing_subscriber::Layerthat feeds every event into aFlightRecorder. - Level
Trigger - Fires when an event’s severity is at or above a configured
Level. - Once
Trigger - Decorator that allows an inner trigger to fire at most once until reset.
- Span
Context - The context of a single span in the hierarchy when an event fires.
Enums§
- Dump
Source - What kind of code path triggered a dump.
Constants§
- DEFAULT_
CAPACITY - Default ring-buffer capacity (number of events).
- DUMP_
SCHEMA_ VERSION - Current
FlightRecorderDumpenvelope schema version.
Traits§
- Trigger
- A predicate that decides whether the buffer should be dumped for a given event.