feat: carry the signed-in user and tenant on telemetry, and send a final event on opt-out
Issue for this PR
Type of change
- New feature
What does this PR do?
- Identity. When the machine is signed in to Altimate, every row carries
user_idandtenant, and the user uuid becomes the App Insights user id. Anonymous rows keep the machine id. The identity is resolved once per stored credential through the users/me call and cached owner-only under a fingerprint of the credential. A changed credential, a sign-out or a 401/403 drops it. A transient failure is retried after 60 s, a rejected key is not looked up again until it changes, and a stale answer is discarded. No email, hashed or not, leaves the client. Backend calls name the CLI version in a header. - Opt-out. When telemetry is disabled by environment or config, a machine that already has a machine id sends one final
telemetry_opted_outevent, then nothing. It carries the machine id and the opt-out source, never the account. An in-flight claim file makes it one send across threads and processes. A marker next to the machine id is written only after the ingest endpoint accepts the event, so an offline launch tries again. Turning telemetry back on clears the marker. - Config opt-out without an Instance. The CLI's main thread initialises telemetry before an Instance exists, so
Config.get()throws there. Init then readstelemetry.disabledfrom the config files directly. If they cannot be read, telemetry stays on, but the marker is kept and no account is resolved. - Docs. The telemetry reference page describes the identity, its cache and lookup, and the opt-out event and its files.
Why
Web events are keyed by the backend user uuid and CLI events only by machine, so nothing joined a CLI session to its account. An opted-out machine also looks exactly like a client that stopped emitting. With the opt-out as its last event, the dashboards can count opt-outs and explain the silence after them.
How did you verify your code works?
- Identity suite: resolution, caching, invalidation, retry backoff, no polling of a rejected key, stale-answer fences and cache file mode against stubbed endpoints. No email in any property.
- Opt-out suite: the single event and its properties, nothing afterwards, no event without a machine id, the marker only after a 2xx, the env and config sources, the force flag, two inits sending once, and an init that cannot read the config keeping the marker.
- Config reader suite: the global, project and inline sources, override order, and unreadable files.
- Typecheck clean; the telemetry suites pass.
Cost side effects
None. The rows gain fixed-size properties, and an opted-out machine sends at most one more event. An init without an Instance reads a few local config files. No model calls, queries or cloud resources grow with user data.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
- I checked for cost side effects (model calls, queries or cloud resources that grow with user data) and described them, or wrote "none"
Held for Ralph
Proposed fix: one pure per-source config parser shared by the loader and the opt-out probe. The probe, TelemetryConfig.disabledState(), already calls the loader's own validation (validateLoaded). Its parse (ConfigPaths.parseText) and its empty-source guard are its own copies, which is where review found the drift. The change is contained:
- Add
parseConfigSource(text, source, env)toconfig/config.ts: the empty-text guard, thenConfigVariable.substitute,ConfigParse.jsoncand validation.loadConfigcalls it and keeps its later steps (plugin resolution, the$schemawrite). Its five callers and everyloadFilecaller stay unchanged. - The one side effect inside the parse, recording blanked env names for
mcp list, gets arecord: falseoption inconfig/variable.tsfor the probe. - Estimate: about 30 lines in those two upstream-shared files, inside
altimate_changemarkers, and about 20 fewer in the probe. - Still a copy afterwards: the list of sources and their order, the directory filter, the git-root lookup, the legacy TOML handling, and no
authEnv.
Supersedes #1500.
🤖 Generated with Claude Code