Include categorized host in telemetry#13250
Conversation
ab709aa to
b0929b5
Compare
babakks
left a comment
There was a problem hiding this comment.
LGTM, with a few suggestions. I'm okay with doing them in a follow-up though, so I'm approving.
There was a problem hiding this comment.
Pull request overview
This PR enhances CLI telemetry by adding a categorized “target host type” dimension to command_invocation events, using a best-effort host inference based on flags/args/env/git/config. It also centralizes telemetry recording in ghcmd.Main and introduces new internal error/exit-code helpers that feed additional telemetry dimensions.
Changes:
- Add host inference (
GuessTargetHost) and recordguessed_host_typein command invocation telemetry. - Move command invocation telemetry recording from per-command wrapping to a single deferred recorder in
internal/ghcmd.Main. - Introduce
internal/gherrserror types/exit codes and add tests for error-type telemetry dimensions and host categorization.
Show a summary per file
| File | Description |
|---|---|
| pkg/cmdutil/telemetry.go | Removes per-command telemetry wrapping; keeps/expands telemetry-disable helpers and exports IsTelemetryDisabled. |
| pkg/cmdutil/telemetry_test.go | Updates tests to cover telemetry-disable behavior instead of command invocation recording. |
| pkg/cmd/root/root.go | Removes recursive subcommand telemetry instrumentation call from root command setup. |
| pkg/cmd/auth/auth.go | Switches to disabling telemetry for auth commands recursively. |
| internal/telemetry/host.go | Adds host-guessing logic to infer the command’s likely target host. |
| internal/telemetry/host_test.go | Adds tests covering host inference priority order and fallbacks. |
| internal/ghinstance/host.go | Ensures empty host categorizes to uncategorized. |
| internal/ghinstance/host_test.go | Adds test for empty-host categorization. |
| internal/gherrs/errors.go | Introduces internal error/exit-code abstractions used by ghcmd.Main. |
| internal/ghcmd/cmd.go | Centralizes telemetry recording (including host type + error dims) and refactors error handling/exit code mapping. |
| internal/ghcmd/cmd_test.go | Adds tests for error-type collection, err-dimension logic, and end-to-end telemetry capture. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comments suppressed due to low confidence (2)
internal/ghcmd/cmd_test.go:474
- This test asserts the wrapper type name "fmt.wrapError" in errTypes. Wrapper type names are not a stable API and can change between Go versions/toolchains, making this assertion brittle; consider asserting only that the terminal domain error type (e.g. "gherrs.silentError") is present.
name: "single fmt wrap",
err: fmt.Errorf("context: %w", gherrs.SilentError),
want: "fmt.wrapError,gherrs.silentError",
},
internal/ghcmd/cmd_test.go:479
- This case also hard-codes "fmt.wrapError" in the expected errTypes output. To reduce brittleness across Go/toolchain changes, consider loosening the assertion to focus on your own error type(s) and general shape rather than exact stdlib wrapper names.
name: "double fmt wrap",
err: fmt.Errorf("outer: %w", fmt.Errorf("inner: %w", gherrs.SilentError)),
want: "fmt.wrapError,fmt.wrapError,gherrs.silentError",
},
- Files reviewed: 11/11 changed files
- Comments generated: 3
daac0e1 to
d878b17
Compare
a6b8b97 to
df7e15b
Compare
- Normalize --hostname flag values via ghauth.NormalizeHostname - Gate baseRepo() call behind --repo flag check to avoid git discovery for non-repo-scoped commands like 'gh version' - Convert TestGuessTargetHost to table-driven test format Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
df7e15b to
393fe08
Compare
b7e0758 to
b77f5f2
Compare
- Extract recordCommandTelemetry into a testable function - Add PersistentPostRun hook on root to capture the real executed command when aliases re-dispatch via root.Execute(), so the expanded command gets telemetry recorded instead of silently skipping it - Add tests for command_invocation recording: normal commands, visited flags, missing command, and telemetry-disabled commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
b77f5f2 to
d725e0a
Compare
|
Actually @babakks I'm thinking maybe we should close this and approach it a different way, where instead of trying to capture this in Not closing right now cause I'd prefer your opinion on it. |
|
So, you're thinking about an explicit new event type (like in |
|
Yes I'm thinking that we will also eventually want a way to tie commands to their |
Description
Categorizes the host that is most likely being targeted as
github.comortenant. It does categorizeGHES, but we turn off telemetry for GHES so we would never expect that to be included.