pub struct TraceWindow { /* private fields */ }Expand description
Sliding window that accumulates events by trace_id.
Uses an LRU cache for O(1) amortized eviction when at capacity.
Implementations§
Source§impl TraceWindow
impl TraceWindow
pub fn new(config: WindowConfig) -> Self
Sourcepub fn push(
&mut self,
event: NormalizedEvent,
now_ms: u64,
) -> Option<(String, Vec<NormalizedEvent>)>
pub fn push( &mut self, event: NormalizedEvent, now_ms: u64, ) -> Option<(String, Vec<NormalizedEvent>)>
Push a normalized event into the window.
Returns the LRU-evicted trace (if any) so the caller can run detection
on it before discarding. Returns None if no eviction was needed.
Sourcepub fn evict(&mut self, now_ms: u64)
pub fn evict(&mut self, now_ms: u64)
Evict traces that have not been updated within the TTL.
Scans the full LRU cache rather than stopping at the first non-expired
entry, because clock adjustments (NTP) can cause last_seen_ms and LRU
position to diverge, leaving expired traces behind non-expired ones.
The key cloning into a temporary Vec<String> is required because
the lru crate does not expose retain() or drain_filter().
At max_active_traces = 10_000 the cost is bounded and runs at
most once per tick (~15s). If the lru crate adds in-place removal
in a future release, this can be simplified.
Sourcepub fn evict_expired(
&mut self,
now_ms: u64,
) -> Vec<(String, Vec<NormalizedEvent>)>
pub fn evict_expired( &mut self, now_ms: u64, ) -> Vec<(String, Vec<NormalizedEvent>)>
Evict expired traces and return them for processing.
Unlike evict() which silently drops expired traces, this method
returns them so the daemon can run detection before discarding.
Scans the full cache to handle clock skew (see evict()).
Sourcepub fn drain_all(&mut self) -> Vec<(String, Vec<NormalizedEvent>)>
pub fn drain_all(&mut self) -> Vec<(String, Vec<NormalizedEvent>)>
Drain all traces, returning their events grouped by trace_id.
Sourcepub fn active_traces(&self) -> usize
pub fn active_traces(&self) -> usize
Number of active traces.
Sourcepub fn peek_clone(&self, trace_id: &str) -> Option<Vec<NormalizedEvent>>
pub fn peek_clone(&self, trace_id: &str) -> Option<Vec<NormalizedEvent>>
Clone a trace’s spans without evicting or promoting it in the LRU.
Returns None if the trace is not in the window.
Auto Trait Implementations§
impl Freeze for TraceWindow
impl RefUnwindSafe for TraceWindow
impl Send for TraceWindow
impl Sync for TraceWindow
impl Unpin for TraceWindow
impl UnsafeUnpin for TraceWindow
impl UnwindSafe for TraceWindow
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request