feat(agent-proxy): add adoption telemetry for agent proxy commands - #341
Conversation
Capture start, connect and run as PostHog events with their deployment shape (sandbox state, unmatched-host policy, sandbox escape-hatch counts, agent executable name). Group CLI events under the organization so usage is attributable, including for commands that authenticate with a client id/secret and therefore have no token in the environment to read.
|
💬 Discussion in Slack: #pr-review-cli-341-feat-agent-proxy-add-adoption-telemetry-for-agent-proxy-comman Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel. |
|
| Filename | Overview |
|---|---|
| packages/cmd/agent_proxy.go | Adds connect telemetry and token-source reporting, but mixed flag/environment universal-auth credentials remain mislabeled. |
| packages/cmd/agent_proxy_run.go | Adds run telemetry describing the sandbox, network fallback, agent executable, and escape-hatch counts. |
| packages/cmd/agent_proxy_start.go | Adds start telemetry while consuming the credential-source classification that remains inaccurate for mixed inputs. |
| packages/telemetry/telemetry.go | Adds attached token identity and organization grouping, with the previously reported precedence defects corrected. |
Reviews (4): Last reviewed commit: "fix(agent-proxy): prefer attached identi..." | Re-trigger Greptile
|
@greptile review |
…ent properties The attached machine identity now outranks a persisted human login, so a machine-identity run on a developer host no longer files the event against the human's person record while grouping it under the machine's org. A user session JWT carries no identityId, so login-backed runs still resolve to the email. Also drops port, logFormat and logFileSet, moves the run capture below the sandbox preflight, and reports netDowngraded so a fence that fell back to shared networking is visible.
|
@greptile review |
1 similar comment
|
@greptile review |
…comments SetActor takes the identity and org ids instead of an access token, so nothing token-shaped crosses into telemetry. Also removes a duplicated comment block and cuts the added comments back.
…n to the set actor
Description 📣
Agent proxy commands emit no telemetry today, and on a proxy host nothing identifies the caller either:
startandconnectauthenticate with a client id/secret, andUniversalAuthLoginholds that token in memory rather than exporting it, soGetDistinctIdfinds nothing in the environment and falls through toanonymous_cli_<machineid>. Standalone proxy usage was unattributable.Events: one per command,
cli-command:agent-proxy start,connectandrun, captured before the long-running work so an attempt is still recorded when the command later dies. Properties describe the deployment shape rather than its contents:unmatchedHost,credentialSource,logFormat/logFileSet,pollIntervalforstart;sandboxEnabledplussandboxSource(flag, env or default) and the--allow-read/--allow-write/--allow-host/--pass-env/--set-envcounts forrun;allowReadableBrokeredSecretsforconnect. The sandbox escape-hatch counts are the useful ones: if most runs re-open three paths, the sandbox defaults are wrong.Attribution:
AttachTokenIdentityrecords the identity and organization claims from a token the command has already resolved, so events are attributed even when nothing is exported in the environment. Events are grouped under$groups.organization, matching theorganizationgroup type the backend sets, which is what makes usage attributable to a company rather than a machine. Both claim spellings are read:orgIdon machine identity tokens,organizationIdon user session JWTs.Agent name: the basename of the first word after
--, and nothing else. argv past the first word routinely carries credentials (-- python train.py --hf-token=hf_...), so the executable name is the only part reported.Companion backend PR: Infisical/infisical#7491
Not in this PR: failure events with a reason enum, since every failure path exits through
util.HandleError→os.Exitand instrumenting them means touching every call site. Session duration and per-request decision rollups are also left out; both need thedefer t.posthogClient.Close()inCaptureEventfixed first, because today the second capture in a process is silently dropped. Both are follow-ups.Type ✨
Tests 🛠️
# Here's some code block to paste some code snippets