Conversation
auth_invocation telemetry on login and refresh
A Ctrl+click on HelperConfig in cli/cli#14673 lists its three declarations, with the sticky header pinning loginRun. It was taken read-only from a release build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
866284b to
b181002
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Telemetry wiring and authentication coverage remain incomplete, helper inspection violates best-effort behavior, and non-interactive output changes unexpectedly.
5 open findings
Re-enable telemetry for login and refresh commands · New Record telemetry for token-based logins · New Handle helper inspection failures without blocking authentication · New Avoid stderr warnings for non-interactive logins · New Record configured credential preference separately from effective intent · New
What changed in this PR
Adds authentication telemetry to support the refreshable-token rollout, building on the expiring-credential preference work.
Changes:
- Passes telemetry recorders into login and refresh.
- Adds auth events covering credential intent, helper state, prompts, storage, and outcomes.
- Adds expiring-login prompts and telemetry tests.
| File | Description |
|---|---|
| pkg/cmd/root/root.go | Passes the recorder into auth commands. |
| pkg/cmd/auth/shared/telemetry.go | Defines auth events and dimension updates. |
| pkg/cmd/auth/shared/telemetry_test.go | Tests event dimensions and gating. |
| pkg/cmd/auth/shared/login_flow.go | Records login outcomes and adds enterprise warnings. |
| pkg/cmd/auth/shared/login_flow_test.go | Tests login telemetry and warnings. |
| pkg/cmd/auth/shared/git_credential.go | Tracks helper state and expiring-login decisions. |
| pkg/cmd/auth/shared/git_credential_test.go | Tests helper prompts and setup. |
| pkg/cmd/auth/refresh/refresh.go | Records refresh context and outcomes. |
| pkg/cmd/auth/refresh/refresh_test.go | Tests refresh telemetry with isolated helpers. |
| pkg/cmd/auth/login/login.go | Forwards telemetry and configures sampling. |
| pkg/cmd/auth/login/login_test.go | Updates constructor calls and helper fakes. |
| pkg/cmd/auth/auth.go | Wires recorders into login and refresh. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| fmt.Fprintf(opts.IO.ErrOut, "%s You were already logged in to this account\n", cs.WarningIcon()) | ||
| } | ||
|
|
||
| authEvent.RecordSuccess() |
There was a problem hiding this comment.
Nit
I think auth_success would be more precise if recorded immediately after successful persistence.
A temporary regression test saved the credential, then failed git setup, but auth_success remained false:
$ go test ./pkg/cmd/auth/shared -run '^TestReview' -count=1
...
--- FAIL: TestReviewStoredCredentialRemainsSuccessfulWhenGitSetupFails (0.00s)
...
expected: "true"
actual : "false"
...
That makes this measure whole-command success rather than credential storage when later setup fails. Non blocking, but recording it after successful persistence would make the dimension match its documented meaning.
There was a problem hiding this comment.
Fixed in the upcoming PR.
| } | ||
|
|
||
| authEvent.RecordStorage(insecureStorageUsed) | ||
| authEvent.RecordExpiringReceived(refreshableCredential != nil) |
There was a problem hiding this comment.
Nit
I think expiring_received would be more precise if recorded before storage.
A temporary regression test returned a refreshable token, then failed storage, but expiring_received was absent:
$ go test ./pkg/cmd/auth/shared -run '^TestReview' -count=1
...
--- FAIL: TestReviewIssuedTokenIsRecordedWhenStorageFails (0.00s)
...
expected: "true"
actual : ""
...
The server's issuance outcome is independent of local persistence. Non blocking, but recording it when the auth flow returns would preserve that distinction.
There was a problem hiding this comment.
Fixed in the upcoming PR.
…ommands Builders and parsers for the Code tab's T3 Code parity: GraphQL viewed marks (read with pullRequest.files, written with markFileAsViewed and unmarkFileAsViewed), REST review comments grouped by line, and the review POST body with LEFT/RIGHT line comments. Fixtures are trimmed from real read-only gh api output for octet#36 and cli/cli#14673. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4122556 to
fa169d9
Compare
An expiring token can only be refreshed when gh is the git credential helper, so an interactive HTTPS login with expiring credentials now presents an up-front prompt offering to configure gh, continue without it, or cancel. The choice is driven by the expiring intent rather than the token the server returns, and Setup honors it without re-prompting. When expiring credentials are requested against a GitHub Enterprise Server host, which may not support them, a warning notes the token may not be expiring. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
Emit a dedicated auth_invocation event for gh auth login and gh auth refresh. It captures the auth command, whether an expiring credential was requested and received, the resolved git protocol, the git credential helper category before and after, the storage type, the gh as credential helper prompt response, and overall success. Detect the configured credential helper before showing the prompt so helper telemetry also covers non interactive and SSH flows. Auth subcommands now emit only auth_invocation and no longer send the generic command_invocation event. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
… helpers DetectConfiguredHelper discarded the read error and mapped a failed lookup to "none", making an unavailable inspection indistinguishable from a genuinely absent helper. Capture the error and report a distinct "error" category, and preserve it in ResultingHelperCategory when no setup replaced the helper. Detection failures still never fail authentication. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
Replace the four-valued gh_as_cred_helper_prompt_resp telemetry dimension with a boolean expiring_setup_cred_helper_cancelled that captures the one response we care about: whether the user cancelled the sign-in at the expiring credential-helper prompt. Polish that prompt to print its long explanation as a warning, like other gh warnings, followed by a short decision question. GitCredentialFlow.Prompt now returns the typed ErrExpiringSetupCredHelperCancelled on cancellation, and the login flow records the dimension before translating it into cmdutil.CancelError. The PromptResult enum, whose value distinctions nothing consumed anymore, is removed in favour of a plain error return. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
fa169d9 to
0452816
Compare

Part of the refreshable tokens work (epic github/gh-cli-and-desktop#349). Stacked on top of #14672.
Description
All
authsubcommands are excluded from telemetry, so today we have no signal about how people authenticate. As we roll out refreshable (expiring) credentials, we want to understand the environmentgh auth loginandgh auth refreshrun in: whether an expiring credential was requested and whether one was received, whether gh is the configured git credential helper, which git protocol is in use, where the credential is stored, and how the sign-in ended.This change records a dedicated
auth_invocationevent from theloginandrefreshcode paths. Every other auth subcommand (status,logout,token,switch,setup-git,gitcredential) stays excluded. Importantly,loginandrefreshdo not emit the genericcommand_invocationevent either: the whole auth subtree is suppressed withDisableTelemetryForSubcommands, andlogin/refreshreport only the richerauth_invocation. So each of those two commands reports exactly one telemetry event, with no duplicatecommand_invocationalongside it, and the remaining auth subcommands report nothing.auth_invocationis begun directly in the command's run, independent of thecommand_invocationannotation gate, and the whole invocation is sampled at 100%.New event type:
auth_invocationDimensions on that event:
auth_command: which command recorded the event, eitherloginorrefresh.expiring_requested: whether an expiring, refreshable token was requested (the effective intent after flags and config),trueorfalse.expiring_received: whether the server actually issued an expiring, refreshable token,trueorfalse.git_protocol: the git operations protocol selected for the host, one ofhttps,ssh, orunset.loginreports the protocol it resolved (interactive selection or the--git-protocolflag), reportingunsetfor a non-interactive login with no flag.refreshreads the host config, which defaults tohttps, so it never reportsunset.git_credential_helper_before: the configured git credential helper for the host before login reconfigured it, one ofours(gh),other(a non-gh helper),none, orerrorwhen the helper could not be read.git_credential_helper_after: the configured git credential helper after the command completed, same four values. For non-interactive and SSH sign-ins no setup runs, so this equals_before.expiring_setup_cred_helper_cancelled: whether the user cancelled the sign-in at the expiring credential-helper prompt,trueorfalse. Onlytruecan be relied upon as a real event: it is set exactly when the user cancels at that prompt.falseis the default dimension value and also covers every invocation that never reached the prompt (non-expiring logins, refreshes, and logins where gh is already the helper), so it must not be read as "the user was asked and chose not to cancel".storage_type: where the credential was stored,keyring(a secure store was used) orplaintext.auth_success: whether a credential was stored successfully,trueorfalse.On an expiring login where gh is not already the credential helper, the flow explains the consequence of not configuring gh (git will not learn about refreshed tokens and HTTPS git operations will start to fail once the token expires) as a standard gh warning, then asks a short decision question: set gh up as the helper, continue without it, or cancel the sign-in. Telemetry only needs to know whether the user cancelled, which is why
expiring_setup_cred_helper_cancelledis a single boolean rather than a record of the full prompt response.Recording is best effort: a nil recorder results in no event, and a failed read of the configured helper is reported as the
errorcategory rather than failing the command. The event is dropped entirely for GitHub Enterprise Server hosts.Key design notes
git configread keyed by hostname) and recordgit_credential_helper_before/_afterunconditionally, before the prompt gate. Previously these were only recorded inside the interactive HTTPS block, so we had no helper signal for exactly the cohort we most want to understand: non-interactive (non-TTY) and SSH sign-ins, where gh never prompts. We deliberately do not cache the read: it is a cheap local process invocation, and reading it independently in the telemetry step and insidePromptkeeps the sequence undictated, soPromptkeeps the git-not-installed abort it relies on. Nothing mutates git config between the two reads, so they stay consistent.command_invocation, mirroring the existingattachment_invocationpattern, so the auth-specific context stays self contained.ours/other/none, pluserrorwhen the read fails) rather than a boolean, so we can distinguish "no helper" from "a non-gh helper" and from "could not tell".GitCredentialFlow.PromptreturnsErrExpiringSetupCredHelperCancelledwhen the user cancels at that prompt; the login flow records the dimension and then translates it into the usualcmdutil.CancelError, so the caller can observe the specific outcome without changing the user-facing cancellation behavior.BeginAuthTelemetrydrops the event forIsEnterprisehosts, and the globalmightBeGHESUsergate already disables the whole telemetry service for likely-GHES users. Withcommand_invocationsuppressed across the auth subtree, no auth telemetry can escape that gate.How did you test this change?
Unit tests cover the event end to end: the dimensions and their values, the enterprise drop, the nil-recorder and nil-helper no-op paths, and the
git_protocolunsetmapping (pkg/cmd/auth/shared/telemetry_test.go), plus the login and refresh flows recording through the shared helper, including the expiring-login cancellation recordingexpiring_setup_cred_helper_cancelled=true(pkg/cmd/auth/shared/login_flow_test.go,pkg/cmd/auth/refresh/refresh_test.go).go test ./...andmake lintpass.For a live check, build the binary and run a login or refresh with telemetry logged to stderr:
The
auth_invocationevent and its dimension values are printed at the end of the run. On an expiring login where gh is not the configured helper, the warning is printed followed by the short decision prompt; choosing Cancel aborts the sign-in and recordsexpiring_setup_cred_helper_cancelled=true.Notes for reviewers
Start at
pkg/cmd/auth/shared/telemetry.go(the event,BeginAuthTelemetry, and theRecord*methods for each dimension), thenpkg/cmd/auth/auth.go(theDisableTelemetryForSubcommandswiring that suppressescommand_invocationfor the whole subtree), then the record call sites inpkg/cmd/auth/shared/login_flow.goandpkg/cmd/auth/refresh/refresh.go, andpkg/cmd/auth/shared/git_credential.gofor the expiring prompt and theErrExpiringSetupCredHelperCancelledseam.Authorship and follow-up
Who wrote this:
Who answers review comments: