feat: add opt-in anonymous telemetry reporting

Add an opt-in telemetry system that sends anonymised instance
statistics to the public API once per day, which proxies them to
PostHog when `POSTHOG_API_KEY` is configured.

- Add `packages/core/src/telemetry.ts` — `performTelemetryReport`
  and `isTelemetryEnabled`; user and title counts are bucketed
  before sending to avoid exposing exact figures
- Add `getInstanceId()` to `settings.ts` — generates and persists a
  stable UUIDv7 for the instance
- Schedule a daily `telemetryReport` cron job (00:30)
- Add `POST /v1/telemetry` to `apps/public-api`; forwards payload
  to PostHog or returns 204 silently if key is absent
- Add `admin.telemetry` and `admin.toggleTelemetry` oRPC procedures
  for inspecting and toggling the setting
- Expose `instanceId` on `system.publicInfo`
This commit is contained in:
2026-03-13 21:14:56 -04:00
parent b7bacb352f
commit 9278ea6e73
10 changed files with 185 additions and 1 deletions
+8
View File
@@ -23,6 +23,14 @@ export function getUserCount(): number {
return result?.count ?? 0;
}
export function getInstanceId(): string {
const existing = getSetting("instanceId");
if (existing) return existing;
const id = Bun.randomUUIDv7();
setSetting("instanceId", id);
return id;
}
export function isRegistrationOpen(): boolean {
const userCount = getUserCount();
if (userCount === 0) return true;