pub struct FileJsonSink {
pub path: PathBuf,
pub file: Arc<Mutex<File>>,
}Expand description
File-backed sink. Records are appended to path as JSONL.
The file is opened once at construction with O_APPEND (or the
platform equivalent) and writes serialise through an inner
std::sync::Mutex. Each emit performs write_all + flush so a
process crash loses at most the in-flight record. See module docs for
the latency rationale.
Fields§
§path: PathBufPath the sink was constructed with — retained for diagnostics.
file: Arc<Mutex<File>>The append-only file handle. std::sync::Mutex (not
tokio::sync::Mutex) because the critical section is sync I/O
with no .await point.
PERF: wrapped in an Arc so AuditSink::emit can hand a cheap
clone of the handle to a tokio::task::spawn_blocking worker and
offload the blocking write_all + flush off the async response
path (see the emit impl below). The Arc is the minimal change
that lets the &self-borrowed mutex outlive the request future on
the blocking pool.
Implementations§
Trait Implementations§
Source§impl AuditSink for FileJsonSink
impl AuditSink for FileJsonSink
Source§fn emit(&self, record: &AuditRecord)
fn emit(&self, record: &AuditRecord)
record. Errors are intentionally absorbed: an audit
failure must never bubble up and corrupt a successful API call.
Implementations should log internally via tracing::error!
instead of propagating.Auto Trait Implementations§
impl Freeze for FileJsonSink
impl RefUnwindSafe for FileJsonSink
impl Send for FileJsonSink
impl Sync for FileJsonSink
impl Unpin for FileJsonSink
impl UnsafeUnpin for FileJsonSink
impl UnwindSafe for FileJsonSink
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>
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
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> 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