feat(telemetry): org attribution, agent user-agent, and working opt-out - #360
Draft
claude[bot] wants to merge 1 commit into
Draft
feat(telemetry): org attribution, agent user-agent, and working opt-out#360claude[bot] wants to merge 1 commit into
claude[bot] wants to merge 1 commit into
Conversation
…pt-out - CaptureEvent now sets a flat organizationId property (alongside the existing PostHog group) resolved offline from either the logged-in user's session JWT (organizationId claim) or a machine-identity access token in the environment (orgId claim), mirroring the distinct-id resolution priority. No server lookups; silent on failure. - The agent now identifies itself as infisical-agent/<version> instead of reusing the interactive CLI's "cli" user-agent, so backend channel attribution can split agent traffic from interactive usage. - --telemetry=false was read in init() before cobra parsed argv, so it never took effect; it is now applied in PersistentPreRun after flag parsing. Added INFISICAL_TELEMETRY_ENABLED env var as an additional opt-out (explicit flag wins over env).
Open
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Andrew Huang · Slack thread
Description 📣
Before:
resolveOrganizationIdonly covered the agent-proxy/env-token paths, and even then the org was attached only as a PostHog group, never as a property, so events from logged-in users and most machine-identity runs cannot be attributed to an organization."cli"user-agent as interactive CLI usage, so agent traffic is indistinguishable from humans running commands.--telemetry=falsesilently does nothing: the flag was read ininit()before cobra parsed argv, so it always returned the registered default and telemetry stayed on.After:
organizationIdproperty (plus the existing PostHog group attach), resolved fully offline from either the logged-in user's session JWT (organizationIdclaim, read from the system keyring) or a machine-identity access token in the environment (orgIdclaim). Resolution priority mirrors the existing distinct-id resolution. No server lookups; fails silently to empty, like the existing claim parsing. Nothing from the token itself is kept.infisical-agent/<version>(reusing the CLI's ldflags-injected version variable). Interactive CLI keeps the"cli"user-agent.--telemetry=falseis now applied inPersistentPreRunafter flag parsing, and a newINFISICAL_TELEMETRY_ENABLEDenvironment variable is honored as well (an explicitly set flag wins over the env var; default remains enabled).Privacy note for reviewers: the opt-out fix deserves attention on its own. Users who passed
--telemetry=falsehave been opted in anyway because the flag was silently inert. That is a trust issue, not just a bug, and it is fixed here along with adding the env-var opt-out for CI and container use.Paired backend PR: a companion backend change maps the
infisical-agentuser-agent prefix to its own channel server-side so agent traffic is split out of theclichannel. This PR and that one are independent to ship, but attribution of agent traffic only improves once both land.How
packages/telemetry/telemetry.go:CaptureEventsets the flatorganizationIdproperty;resolveOrganizationIdgains a logged-in-user step (newloggedInUserOrganizationIdhelper reading the keyring credentials and decoding claims with the existingIdentityClaimsFromToken); newSetEnabledmethod so opt-out surfaces can be applied after flag parsing.packages/cmd/root.go: telemetry enablement resolved after argv parsing (resolveTelemetryEnabledinPersistentPreRun), env-var evaluation at construction time (telemetryEnabledFromEnv), flag help text updated.packages/cmd/agent.go: newAGENT_USER_AGENT = "infisical-agent/" + util.CLI_VERSION, used at all five agent SDK-client construction sites (replacesapi.USER_AGENTand resolves the existing TODO asking for a distinct agent user-agent).packages/util/constants.go:INFISICAL_TELEMETRY_ENABLED_NAMEconstant, following the existingINFISICAL_*naming convention.Type ✨
Tests 🛠️
go build ./...passes.go vetclean for the touched packages (packages/telemetry,packages/util); the remaining vet findings (packages/cmd/run.go,packages/gateway-v2,packages/pam/handlers/kubernetes) pre-exist onmain, verified against the unmodified baseline.go test ./packages/util/... ./packages/cmd/...passes (packages/cmdrequires-vet=offdue to the pre-existingrun.govet findings;packages/telemetryhas no test files).orgIdclaim), user session token (organizationIdclaim),st.service token, and garbage input all resolve as expected.infisical --telemetry=false --versionandINFISICAL_TELEMETRY_ENABLED=false infisical --versionboth run clean.Generated by Claude Code