feat(ludic.telemetry): an event queue batched to a PostHog-shaped endpoint
Events are encoded once into lines held in memory; a batch is the first lines joined, with the player id put in where a mark stood, POSTed on Http's own thread every flush_ms or at flush_at events; a failure keeps its lines and doubles the wait up to backoff_max; the queue is on disk every save_ms and read back at the next start; off (the enabled port) drops the request in flight, empties the queue and deletes the file; and a run that may not send (can_send) keeps nothing. The player id is the machine's own id (MachineGuid, IOPlatformUUID, /etc/machine-id) hashed with the game's salt, else random; it lives in the game's id file beside whatever else the game keeps there. Ports: TelemetryWorld (can_send, enabled, now_ms, stamp) and TelemetryTransport (send, poll, drop; unbound: Http). Config is a record (host, key, path, lib, queue_file, id_file, id_salt, and the timings). Facts: TELEMETRY_SENT, _FAILED, _ID. Not a System: it runs from a launcher's first frame, before any world exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
cac8c740fa
commit
e8c1d54a96
10 changed files with 711 additions and 0 deletions
33
packages/ludic.telemetry/queries.ludic
Normal file
33
packages/ludic.telemetry/queries.ludic
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# queries.ludic - what the game (a Settings row, a test) asks, and a reset back to before start
|
||||
export function telemetry_id() -> string { return telemetry__id }
|
||||
export function telemetry_session() -> string { return telemetry__session }
|
||||
export function telemetry_ready() -> bool { return telemetry__ready }
|
||||
export function telemetry_get_config() -> TelemetryConfig { return telemetry__conf() }
|
||||
export function telemetry_fails() -> int { return telemetry__fails }
|
||||
export function telemetry_next_ms() -> int { return telemetry__next_ms }
|
||||
export function telemetry_in_flight() -> bool { return telemetry__h >= 0 }
|
||||
|
||||
export function telemetry_queued() -> int {
|
||||
if telemetry__q == null { return 0 }
|
||||
return len(telemetry__q)
|
||||
}
|
||||
|
||||
# a queued line as it will be sent, player mark and all
|
||||
export function telemetry_line(i: int) -> string { return telemetry__q[i] }
|
||||
|
||||
# back to before telemetry_start, ports and config kept (tests; a start after a failed boot)
|
||||
export function telemetry_reset() -> void {
|
||||
telemetry__drop_request()
|
||||
telemetry__ready = false
|
||||
telemetry__id = ""
|
||||
telemetry__session = ""
|
||||
telemetry__q = null
|
||||
telemetry__dirty = false
|
||||
telemetry__sent_n = 0
|
||||
telemetry__next_ms = 0
|
||||
telemetry__saved_ms = 0
|
||||
telemetry__fails = 0
|
||||
telemetry__clock_on = false
|
||||
telemetry__proc = -1
|
||||
q_clear(telemetry_facts())
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue