Stats¶
stats
¶
Local usage-event collection and periodic flush to a remote endpoint.
Events are appended as JSON lines to ~/.local/share/oops/stats.jsonl.
A flush is attempted at CLI startup when the last successful flush was more
than 7 days ago. All I/O errors are silently swallowed so the feature never
blocks normal CLI operation.
Functions:
| Name | Description |
|---|---|
append_event |
Append one usage event as a JSON line to the stats file. |
flush_stats |
Read all pending events, POST them to the configured endpoint, then truncate. |
maybe_flush |
Flush pending events if the last flush was more than 7 days ago. |
append_event
¶
Append one usage event as a JSON line to the stats file.
Silently does nothing if stats are disabled or any I/O error occurs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
Command identifier, e.g. |
required |
|
float
|
Elapsed time in milliseconds. |
required |
|
str | None
|
Exception class name if the command raised, otherwise |
required |
Source code in src/oops/services/stats.py
flush_stats
¶
Read all pending events, POST them to the configured endpoint, then truncate.
Args are read from config.stats. Raises on HTTP or I/O errors so that
:func:maybe_flush can catch and swallow them silently.
Source code in src/oops/services/stats.py
maybe_flush
¶
Flush pending events if the last flush was more than 7 days ago.
Silently does nothing when stats are disabled, the flush is not due yet, or any error occurs.