English
core/telemetry/telemetry.ts
Generated from the exports of core/telemetry/telemetry.ts · npm run docs:gen
Telemetry (docs/oss/TELEMETRY.md): opt-in, off until the person answers, minimal. The only network code of the CLI and the server that is not a command the person typed. Shared by alta (bundled) and the server (type stripping): erasable TypeScript only. The one module of core/ that uses Node (fs, fetch): the packages leave it out of their type checks (packages//tsconfig.json), and none of them imports it. Nothing is sent unless ALL of these hold: - the person answered "yes" (alta telemetry on, the game's question or its setting); no answer = off; - DO_NOT_TRACK is not set (any value but "", "0" or "false" turns telemetry off, whatever the answer); - a project key is configured: ALTA_TELEMETRY_KEY, or projectKey in ~/.config/alta/telemetry.json. No key is committed anywhere; without one, this module sends nothing; - the event is in the closed list below, with only its allowed properties. The payload holds: a random install id (made when the person says yes, dropped when they say no), the app ("cli", "server"), its version, the OS family, the event, and for chart.installed the chart's locality. Never a chart id, a quest id, a path, a name, a prompt, a secret, an address or the machine's name. PostHog is told not to look up the address ($geoip_disable) and not to build a person profile; the project must also discard client IPs.
Standards that cite this file: No standard page cites this file yet.
Exports
TELEMETRY_SCHEMA const
ts
const TELEMETRY_SCHEMA = "alta.telemetry/0.1"DEFAULT_HOST const
PostHog's EU cloud. ALTA_TELEMETRY_HOST replaces it (https only; http://127.0.0.1 only with ALTA_TEST_HTTP=1).
ts
const DEFAULT_HOST = "https://eu.i.posthog.com"CAPTURE_PATH const
ts
const CAPTURE_PATH = "/i/v0/e/"TIMEOUT_MS const
ts
const TIMEOUT_MS = 3000TELEMETRY_EVENTS const
The closed list of events, and the properties each may carry with their allowed values.
ts
const TELEMETRY_EVENTS: Record<string, Record<string, readonly string[]>>APPS const
ts
const APPS = ["cli", "server"] as constALLOWED_PROPERTIES const
Every key a payload's properties may hold: the base fields, the events' own fields, PostHog's two switches.
ts
const ALLOWED_PROPERTIES = ["app", "version", "os", "locality", "$geoip_disable", "$process_person_profile"]Env type
ts
type Env = Record<string, string | undefined>;Answer type
ts
type Answer = "yes" | "no";TelemetryState interface
ts
interface TelemetryState { schema: string; answer?: Answer; installId?: string; answeredAt?: string; projectKey?: string }Reason type
ts
type Reason = "sent" | "not-answered" | "off" | "do-not-track" | "no-key" | "bad-host" | "unknown-event" | "failed";Status interface
ts
interface Status { enabled: boolean; answer?: Answer; reason: Reason; host: string; file: string }telemetryFile const
ts
const telemetryFile = (env: Env = process.env) => …readState function
ts
function readState(env: Env = process.env): TelemetryStatewriteAnswer function
Records the person's answer. "yes" makes an install id if none; "no" drops it (no identifier is kept).
ts
function writeAnswer(answer: Answer, env: Env = process.env, now = new Date()): TelemetryStateanswered const
ts
const answered = (env: Env = process.env) => …doNotTrack function
DO_NOT_TRACK=1 (https://consoledonottrack.com): any value but "", "0" or "false" turns telemetry off.
ts
function doNotTrack(env: Env = process.env): booleanhostOf function
ts
function hostOf(env: Env = process.env): string | nullstatus function
ts
function status(env: Env = process.env): StatusosFamily function
ts
function osFamily(platform: string = process.platform): stringcleanProps function
The properties an event may carry: only those of its row, only their allowed values; anything else is dropped.
ts
function cleanProps(event: string, props: Record<string, unknown> = {}): Record<string, string> | nullPayload interface
ts
interface Payload {
api_key: string; event: string; distinct_id: string; timestamp: string;
properties: Record<string, string | boolean>;
}payloadFor function
The exact body that would be sent, or why nothing would be.
ts
function payloadFor(event: string, props: Record<string, unknown>, ctx: { app: (typeof APPS)[number]; version: string; env?: Env; now?: Date }):
{ payload: Payload; url: string } | { reason: Reason }track function
Sends one event if telemetry is on. Never throws, never waits more than TIMEOUT_MS, never retries.
ts
async function track(event: string, props: Record<string, unknown>, ctx: { app: (typeof APPS)[number]; version: string; env?: Env; now?: Date; fetchImpl?: typeof fetch }):
Promise<{ sent: boolean; reason: Reason }>