Struct SegmentWriter
pub struct SegmentWriter<Mode = Disk>where
Mode: BufferMode,{ /* private fields */ }dial9 only.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§
§impl SegmentWriter
impl SegmentWriter
pub 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.
pub fn single_file(path: impl Into<PathBuf>) -> Result<SegmentWriter, Error>
pub fn single_file(path: impl Into<PathBuf>) -> Result<SegmentWriter, Error>
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.
pub 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).
§impl SegmentWriter<Memory>
impl SegmentWriter<Memory>
pub fn new(max_total_size: u64) -> Result<SegmentWriter<Memory>, Error>
pub fn new(max_total_size: u64) -> Result<SegmentWriter<Memory>, Error>
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.
pub fn builder() -> MemoryBufferBuilder
pub fn builder() -> MemoryBufferBuilder
Builder for in-memory writer configuration.
§impl<M> SegmentWriter<M>where
M: BufferMode,
impl<M> SegmentWriter<M>where
M: BufferMode,
pub 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.
pub 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.
pub fn trace_stem(&self) -> &str
pub fn trace_stem(&self) -> &str
Segment filename stem, e.g. trace for trace.0.bin.
pub fn current_active_path(&self) -> &Path
pub fn current_active_path(&self) -> &Path
The path of the currently active (being-written) segment file.
§impl<M> SegmentWriter<M>where
M: BufferMode,
impl<M> SegmentWriter<M>where
M: BufferMode,
pub 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§
§impl<M> Debug for SegmentWriter<M>where
M: BufferMode,
impl<M> Debug for SegmentWriter<M>where
M: BufferMode,
§impl<M> Drop for SegmentWriter<M>where
M: BufferMode,
impl<M> Drop for SegmentWriter<M>where
M: BufferMode,
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more