Upload pending crash reports as opt-in telemetry

A crash report is worth nothing sitting on the player's disk. On startup, drain
the crash_report_*.txt files the handler left behind to the endpoint named by
CRASH_TELEMETRY_URL in Ja2 Settings; an empty or absent key turns the feature off
entirely. The first launch asks the player once and remembers the answer in
telemetry.consent -- declined means the reports simply keep accumulating locally.

This lands in its own translation unit rather than in more of debug_win_util.cpp.
Everything in that file runs inside a faulting thread and may not allocate;
everything here runs at startup with a healthy heap and is ordinary code. Two
files keep the no-heap rule easy to see and easy to hold.

The draining runs on a detached thread. The uploads are synchronous WinHttp calls
with seconds-long timeouts, and this sits on the startup path, so on the main
thread an unreachable endpoint is a stall the player watches before the splash
screen. Nothing waits on the result: if the player quits first the process exits
from under the thread, which costs nothing, since an interrupted upload leaves the
file on disk and it goes out next launch. The consent prompt stays on the main
thread on purpose -- it is a question, and a question has to be asked before
anything is sent.

Which reports get deleted is chosen so that a mistake cannot destroy them. A file
goes away on 2xx, and on 400/413/415, i.e. content the server will never accept.
Everything else keeps it: no connection, 5xx, and notably the 403/404 of a
mistyped CRASH_TELEMETRY_URL, which would otherwise silently eat every player's
crash history. Bounds all round: every WinHttp phase has a timeout, a report over
256 KB is not one of ours and never goes on the wire, at most 20 uploads per
launch so a crash-looping build cannot turn startup into an upload session, and
reports older than 30 days are dropped unsent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Marco Antonio J. Costa
2026-07-28 10:25:47 -03:00
committed by majcosta
co-authored by Claude Opus 5
parent 71cc553a07
commit f5782dccbd
5 changed files with 187 additions and 0 deletions
+5
View File
@@ -948,6 +948,11 @@ void GetRuntimeSettings( )
oProps.initFromIniFile(GAME_INI_FILE);
PopulateSectionFromCommandLine(oProps, "Ja2 Settings");
// Upload crash reports from previous runs (first launch asks the player).
// Empty CRASH_TELEMETRY_URL = off. Runs here, at startup, never in a crash.
sgp::processCrashTelemetry(
oProps.getStringProperty("Ja2 Settings", L"CRASH_TELEMETRY_URL").c_str());
// Optional player handle stamped into crash reports written from here on, so a
// report can be tied to whoever raises it with us. Unset = field omitted.
sgp::setCrashUserHandle(