Expand description
Structured per-request API telemetry.
Opt-in via the telemetry config key (off | basic | full).
Writes one JSON record per API call to ~/.cache/synaps/api-log.jsonl
(mode 0600, O_NOFOLLOW — same hardening as the legacy usage log).
basic records timing, usage, an estimated cost_usd (from
agent_core::pricing), the persisted conversation id (session_id,
the ~/.synaps-cli/sessions/<id>.json id) and the request-trace
correlation ids (runtime_session_id / turn_id / trace_request_id),
so a record joins both its session and its request-trace.jsonl line.
Worker records also carry the worker’s identity (worker_agent,
worker_handle, parent_session_id, parent_runtime_session_id).
After an automatic context rollover a record names its context window
(rollover_window), and the window’s first request says rollover: true.
full additionally records rate-limit headers. The cache_diag verdict
is present at either level when cache_diagnostics is on.
Optional fields are omitted when unknown — never written as 0.
Writes are best-effort and non-blocking: persistence goes through the
bounded background writer (Task 11, spec §6.5), so a slow or broken
log path can never delay or fail the request pipeline. Failures are
counted (never silent-and-invisible) with one warning per persistent
failure class.
Modules§
- writer
- Bounded, non-blocking background writer for observability persistence (Task 11, spec §6.5).
Structs§
- Cache
Diag Record - Cache-diagnostics result (beta
cache-diagnosis-2026-04-07). Only present when the user opted in viacache_diagnostics = true. - Context
Record - Request-shape context: what we sent, for correlating cache behavior.
- Rate
Limit Record - Rate-limit headroom captured from
anthropic-ratelimit-*response headers. Only recorded atfulllevel. - Record
Stamp - Identity fields a
TelemetryWriterhandle stamps onto every record enqueued through it: the persisted conversation id of the session (seeRuntime::request_telemetry) and, on worker handles, who the worker is (seeWorkerTelemetry::worker_writer). - Rollover
Stamp - What a turn request tells its telemetry record about context rollover
(see
TelemetryRecord::rollover_window). - Telemetry
Record - One JSONL record per API call.
- Telemetry
Writer - Cloneable handle to the bounded background writer.
- Usage
Record - Token usage for one API call, including the cache-creation TTL breakdown.
- Worker
Telemetry - The parent session’s telemetry, handed to the subagents it spawns.
- Write
Gate - A gate the writer’s worker waits on before each job (
WriterOptions::write_gate). Starts closed;openreleases the worker for good. - 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.
- Telemetry
Level - Telemetry verbosity level, parsed from the
telemetryconfig key.
Constants§
- DEFAULT_
MAX_ FILE_ BYTES - Default per-file size cap before rotation (matches the legacy writer).
- DEFAULT_
MAX_ GENERATIONS - Default rotated generations kept per log: one (
<path>.1), the historical behaviour. Raised by thetelemetry_log_generationsconfig key. - 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.
- RETRY_
DELAY_ CAP - Maximum delay we’ll honour from any rate-limit header. A pathological reset timestamp far in the future would otherwise stall the turn indefinitely.
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. - ratelimit_
from_ headers - Extract rate-limit headroom from response headers.
- request_
id_ from_ headers - Extract the
request-idresponse header. - retry_
delay_ from_ headers - Compute how long to wait before the next retry, consulting response headers.