pub struct SegmentWriter<Mode: BufferMode = Disk> { /* private fields */ }Expand description
A writer that rotates trace segments to bound resource usage and time.
Generic over backend: use DiskBuffer (files) or MemoryBuffer.
Rotation triggers when either condition is met:
max_file_size: the active segment exceeds this many bytesrotation_period: this much monotonic time has elapsed since the writer (or the previous rotation) started (default: 1 minute)
Prefer time-based rotation. Time-based rotation is coordinated with the
flush loop: thread-local buffers are drained before the segment is sealed,
so each segment contains events from a clean, non-overlapping time window.
Size-based rotation fires immediately when the threshold is crossed and does
not drain thread-local buffers, so segments may contain events that overlap
in time. Set max_file_size large enough that time-based rotation fires
first under normal conditions (e.g. 100 MB or more). Size-based rotation
then acts as a safety valve for unexpected data bursts. When using
DiskBuffer::builder without specifying max_file_size, it
defaults to min(100 MiB, max_total_size / 4) on disk.
max_total_size is the retention budget across closed segments. The
oldest segments are dropped once the total exceeds this budget.
The trace lives in a directory (dir); disk segments are named
{dir}/{stem}.0.bin, {dir}/{stem}.1.bin, etc., each a self-contained
trace with its own header. Rotating writers use the stem trace;
single_file takes the stem from the given file name.
Implementations§
Source§impl SegmentWriter<Disk>
impl SegmentWriter<Disk>
Sourcepub fn set_namespace(&mut self, boot_id: String, lock: File)
pub fn set_namespace(&mut self, boot_id: String, lock: File)
Set the namespace for this writer:
boot_id: The boot id for the namespace.lock: The lock file for the namespace.
Sourcepub fn single_file(path: impl Into<PathBuf>) -> Result<Self>
pub fn single_file(path: impl Into<PathBuf>) -> Result<Self>
Create a writer that writes to a single file with no rotation or eviction.
The segment is written to {stem}.0.bin.active while active, then sealed
to {stem}.0.bin on finalize. The background worker will symbolize
and gzip it to {stem}.0.bin.gz.
Note: This API does not allow the ability to provide custom segment metadata. Time-based rotation is disabled.
Sourcepub fn builder<I1>() -> DiskBufferBuilder<I1>
pub fn builder<I1>() -> DiskBufferBuilder<I1>
Create a DiskBufferBuilder for advanced configuration.
When max_file_size is omitted, it defaults to
min(100 MiB, max_total_size / 4).
Source§impl SegmentWriter<Memory>
impl SegmentWriter<Memory>
Sourcepub fn new(max_total_size: u64) -> Result<Self>
pub fn new(max_total_size: u64) -> Result<Self>
Create an in-memory writer with a total byte budget. Segments live in process heap
instead of files. Auto-picks a reasonable segment size,
use builder for explicit control.
Same rotation semantics as the disk path. Errors when
max_total_size == 0.
Sourcepub fn builder() -> MemoryBufferBuilder
pub fn builder() -> MemoryBufferBuilder
Builder for in-memory writer configuration.
Source§impl<M: BufferMode> SegmentWriter<M>
impl<M: BufferMode> SegmentWriter<M>
Sourcepub fn boot_id(&self) -> Option<&str>
pub fn boot_id(&self) -> Option<&str>
Per-process boot identifier, if namespace isolation is active. This is
the name of the trace_dir subdirectory.
Sourcepub fn trace_dir(&self) -> &Path
pub fn trace_dir(&self) -> &Path
Directory this writer’s trace segments live in. When namespace
isolation is active this is the per-process {configured_dir}/{boot_id}/
subdirectory; otherwise it is the configured directory directly. Use
this to locate the segment files on disk.
Sourcepub fn trace_stem(&self) -> &str
pub fn trace_stem(&self) -> &str
Segment filename stem, e.g. trace for trace.0.bin.
Sourcepub fn current_active_path(&self) -> &Path
pub fn current_active_path(&self) -> &Path
The path of the currently active (being-written) segment file.
Source§impl<M: BufferMode> SegmentWriter<M>
impl<M: BufferMode> SegmentWriter<M>
Sourcepub fn update_segment_metadata(
&mut self,
entries: impl IntoIterator<Item = (String, String)>,
)
pub fn update_segment_metadata( &mut self, entries: impl IntoIterator<Item = (String, String)>, )
Merge the segment metadata entries written into the next rotated segment.
Accepts any iterator so callers can drain a reused buffer (retaining its
capacity) instead of handing over an owned Vec. A Vec still works.
Trait Implementations§
Source§impl<M: BufferMode> Debug for SegmentWriter<M>
impl<M: BufferMode> Debug for SegmentWriter<M>
Source§impl<M: BufferMode> Drop for SegmentWriter<M>
impl<M: BufferMode> Drop for SegmentWriter<M>
Auto Trait Implementations§
impl<Mode> Freeze for SegmentWriter<Mode>where
PhantomData<Mode>: Freeze,
impl<Mode> RefUnwindSafe for SegmentWriter<Mode>where
PhantomData<Mode>: RefUnwindSafe,
impl<Mode> Send for SegmentWriter<Mode>where
PhantomData<Mode>: Send,
impl<Mode> Sync for SegmentWriter<Mode>where
PhantomData<Mode>: Sync,
impl<Mode> Unpin for SegmentWriter<Mode>where
PhantomData<Mode>: Unpin,
impl<Mode> UnsafeUnpin for SegmentWriter<Mode>where
PhantomData<Mode>: UnsafeUnpin,
impl<Mode> UnwindSafe for SegmentWriter<Mode>where
PhantomData<Mode>: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<V, F> ValueFormatter<&V> for F
impl<V, F> ValueFormatter<&V> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &&V)
fn format_value(writer: impl ValueWriter, value: &&V)
value to writerSource§impl<V, F> ValueFormatter<Arc<V>> for F
impl<V, F> ValueFormatter<Arc<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Arc<V>)
fn format_value(writer: impl ValueWriter, value: &Arc<V>)
value to writerSource§impl<V, F> ValueFormatter<Box<V>> for F
impl<V, F> ValueFormatter<Box<V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Box<V>)
fn format_value(writer: impl ValueWriter, value: &Box<V>)
value to writerSource§impl<V, F> ValueFormatter<Cow<'_, V>> for F
impl<V, F> ValueFormatter<Cow<'_, V>> for F
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
fn format_value(writer: impl ValueWriter, value: &Cow<'_, V>)
value to writerSource§impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
impl<V, F> ValueFormatter<Option<V>> for Fwhere
F: ValueFormatter<V> + ?Sized,
Source§const SHAPE: FieldShape<'static>
const SHAPE: FieldShape<'static>
metrique_require_explicit_impls only.Source§fn format_value(writer: impl ValueWriter, value: &Option<V>)
fn format_value(writer: impl ValueWriter, value: &Option<V>)
value to writer