Expand description
Bounded, non-blocking background writer for observability persistence (Task 11, spec §6.5).
One cloneable TelemetryWriter handle serves BOTH record kinds:
- legacy per-request
TelemetryRecords → the existing~/.cache/synaps/api-log.jsonl(format unchanged: one raw JSON object per line, exactly what the old synchronouswrite_recordproduced); - metadata-only
RequestTraces (Tasks 7–10) → a private trace log at~/.cache/synaps/request-trace.jsonl. Each line is the unwrappedsynaps-request-trace/1object, so any schema-aware reader can parse lines directly.
Design contract:
- Never blocks the request path. Enqueue is a
try_sendon a bounded queue; overflow increments a dropped counter (never waits). No awaits, no hidden runtime dependency — the worker is a dedicated OS thread, so sync contexts can enqueue too. - Single-owner writes. Only the worker thread touches the files, so size-capped rotation is concurrency-safe by construction.
- Private files. All paths use the Phase 1
private_fshelpers: parent0700, file0600,O_NOFOLLOW(a planted symlink is refused, never followed). - Observable, quiet failure. Atomic counters for enqueued/written/dropped/serialization/I-O failures; at most one warning per persistent failure class (queue overflow, serialization, open/write, rotate). Warnings carry a class label only — never record content or paths. The open/write latch re-arms after a successful write so a new persistent failure warns again.
- Bounded shutdown.
TelemetryWriter::shutdownstops intake, drains until the deadline, and returns typed stats. Dropping the last handle simply disconnects the queue: the worker drains what is buffered and exits detached —Dropcan never hang.
Production wiring rule (documented until Task 12 adds explicit trace
config/UI): telemetry basic/full enables BOTH legacy telemetry
persistence and metadata-only trace persistence through this writer;
off disables both. The trace schema is structurally metadata-only, so
this can never silently persist raw content.
Structs§
- Telemetry
Writer - Cloneable handle to the bounded background writer.
- Writer
Options - Writer configuration.
Nonepaths resolve to the installation defaults. - Writer
Stats - Snapshot of the writer’s atomic counters.
- Writer
Trace Sink - Production
TraceSink: enqueues each record onto the shared writer.
Enums§
- Shutdown
Outcome - Typed result of a bounded shutdown flush.
Constants§
- DEFAULT_
MAX_ FILE_ BYTES - Default per-file size cap before rotation (matches the legacy writer).
- DEFAULT_
QUEUE_ CAPACITY - Default bounded queue capacity: deep enough that a briefly slow disk never drops records, small enough to bound memory (records are boxed).
- DEFAULT_
SHUTDOWN_ FLUSH_ TIMEOUT - Default budget for the shutdown flush at process-exit epilogues (Task 11): long enough for a healthy disk to drain a full queue, short enough that a hung filesystem can never stall a clean exit.
Functions§
- default_
telemetry_ log_ path - Default telemetry log path:
~/.cache/synaps/api-log.jsonl. - default_
trace_ log_ path - Default trace log path:
~/.cache/synaps/request-trace.jsonl.