Skip to content

Report the account a token-less command would use in telemetry - #113

Open
zmofei wants to merge 6 commits into
mainfrom
telemetry-account-every-command
Open

zmofei wants to merge 6 commits into
mainfrom
telemetry-account-every-command

Conversation

@zmofei

@zmofei zmofei commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

Commands that use no token (--version, doctor, generate-skills, ...) send telemetry without auth, so a logged-in user's account only shows up on API commands. These events now report the token an API command would use, in the same order (--token, then MAPBOX_ACCESS_TOKEN unless --use-login, then the --profile login). The event schema is unchanged.

  • The API commands and this fallback share auth::resolve_source.
  • The login is read only when an event is sent, without refreshing or locking it.
  • Help/version runs with --token, --profile or --use-login on the command line report nothing, since clap didn't parse those values.
  • auth logout reports the account it logged out.
  • report sent with the CLI's own token reports no auth.

Verified: cargo test passes, with end-to-end tests for each case; reverting each fix fails its test. Not verified: a real event in Athena; Windows (CI only).

A command that resolves no token, such as --version, doctor or
generate-skills, sent its event with no auth, so a logged-in user's events
named their account only when they called an API. Such events now report
the token an API command would use, resolved in the same order: --token,
then MAPBOX_ACCESS_TOKEN unless --use-login, then the login for --profile.

The service arms and this fallback now share auth::resolve_source, so the
order cannot drift. The login is read only when an event is sent, without
refreshing it or taking its lock. Help and version runs clap answers itself
report nothing when their command line chooses a token, since it can't be
read.
`report` returns before set_token when the CLI's token serves it, so the
fallback named the user's login as the token the run sent. Clear the
candidates on that path. Also drop a per-word format! in the argv check and
correct the environment candidate's doc.
@zmofei
zmofei requested a review from a team as a code owner October 23, 2026 08:06
A query commands search refuses after clap parsed it went through
set_unparsed, whose argv scan gave up on --profile; it now reads the token
candidates from the parse. logout removed the login before the event read
it, so it now records the token it removes, read first.
mattpodwysocki
mattpodwysocki previously approved these changes Oct 23, 2026

@mattpodwysocki mattpodwysocki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice change, and the privacy side holds up well. The account comes from decoding the token locally, the login is only read after the opt-out check, there's no refresh or lock, and the event still goes out with the CLI's own token. The report-with-CLI-token and logout cases are good catches, and backing out of unparsed help runs instead of guessing feels right.

One thing to fix before merging: the "Privacy" section further down the README (around line 696) still says "the kind of token it used and the Mapbox account that token belongs to". Could you add the same note there that you added under "Each run also sends one event", so both spots say what we actually collect?

One question, not blocking: since the schema doesn't change, an event can't tell "used this token" apart from "would have used it". Anyone counting secret-token usage or splitting by auth.source will now pick up --version and config list runs too. Would a small used: false (or similar) under auth be worth adding so the two stay separable? Happy either way if you think the account is all we need from those runs.

Approving with the README fix. Ran cargo test locally on 5a0099a and everything passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants