Skip to content

Add sampled command telemetry#13191

Merged
williammartin merged 3 commits into
trunkfrom
wm/add-telemetry-to-cli
Apr 17, 2026
Merged

Add sampled command telemetry#13191
williammartin merged 3 commits into
trunkfrom
wm/add-telemetry-to-cli

Conversation

@williammartin

@williammartin williammartin commented Apr 16, 2026

Copy link
Copy Markdown
Member

Description

As per upcoming docs update, changelog and release notes, we're going to start collecting pseudoanonymous client side telemetry. Agents love gh, and we're experiencing massive growth in usage. We need more insight into usage to make better, faster decisions.

Telemetry can be viewed on stderr without being sent by setting GH_TELEMETRY=log or gh config set telemetry log. It can be disabled using GH_TELEMETRY=false, DO_NOT_TRACK=true or gh config set telemetry disabled.

The telemetry is best-effort, spawning a detached subprocess at the end of an invocation. It sampled at 1% across all commands.

This PR requires GH_PRIVATE_ENABLE_TELEMETRY to be set for any telemetry to be sent. This is because we need to communicate through other channels before turning it on.

@williammartin williammartin marked this pull request as ready for review April 16, 2026 19:52
@williammartin williammartin requested a review from a team as a code owner April 16, 2026 19:52

Copilot AI 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.

Pull request overview

Introduces best-effort, pseudoanonymous client-side telemetry for gh command invocations (sampled), with support for logging payloads locally and a hidden subprocess-based sender.

Changes:

  • Add a telemetry service (internal/telemetry) with device ID persistence, common dimensions, sampling, and subprocess flushing.
  • Instrument Cobra commands to record command path + set flags, with opt-outs for sensitive/irrelevant commands.
  • Add hidden gh send-telemetry command and Twirp client/server bindings, plus config/env plumbing and acceptance coverage.
Show a summary per file
File Description
pkg/cmdutil/telemetry.go Adds Cobra RunE instrumentation to record command invocation telemetry.
pkg/cmdutil/telemetry_test.go Unit tests for command instrumentation behavior (flags, sorting, disabled commands).
pkg/cmd/version/version.go Switches version to RunE to work with telemetry instrumentation.
pkg/cmd/send-telemetry/send_telemetry.go Adds hidden send-telemetry command that posts payload batches to the telemetry endpoint.
pkg/cmd/send-telemetry/send_telemetry_test.go Unit tests for send-telemetry option parsing and request formation.
pkg/cmd/root/root.go Wires telemetry recorder into root command subcommands; registers send-telemetry command.
pkg/cmd/root/help_topic.go Documents telemetry-related environment variables in help topics.
pkg/cmd/root/help_test.go Updates root construction in tests to pass a no-op telemetry service.
pkg/cmd/root/extension_registration_test.go Updates root construction in tests to pass a no-op telemetry service.
pkg/cmd/root/extension.go Disables telemetry for extensions and uses cmdutil.DisableAuthCheck.
pkg/cmd/config/list/list_test.go Updates config list expectations to include telemetry setting.
pkg/cmd/completion/completion.go Disables telemetry for completion generation command.
pkg/cmd/auth/auth.go Disables telemetry for auth subcommands.
internal/telemetry/telemetry.go Implements telemetry service, sampling, payload building, and detached subprocess flush.
internal/telemetry/telemetry_test.go Comprehensive tests for device ID persistence, state parsing, flush behavior, and sampling.
internal/telemetry/fake.go Test spy for recording telemetry events.
internal/telemetry/detach_unix.go Unix process detachment implementation for telemetry subprocess.
internal/telemetry/detach_windows.go Windows process detachment implementation for telemetry subprocess.
internal/ghcmd/cmd.go Creates telemetry service based on env/config and injects it into root command creation.
internal/gh/ghtelemetry/telemetry.go Defines shared telemetry interfaces and event types used across packages.
internal/gh/gh.go Extends gh.Config interface with Telemetry() accessor.
internal/gh/mock/config.go Extends config mock to support Telemetry() calls.
internal/config/config.go Adds telemetry config key, accessor, and config option registration.
internal/config/config_test.go Tests telemetry config defaulting and user-provided values.
internal/config/stub.go Wires stub config mock to underlying telemetry config implementation.
internal/barista/observability/telemetry.pb.go Adds generated protobuf types for telemetry ingestion API.
internal/barista/observability/telemetry.twirp.go Adds generated Twirp client/server bindings for telemetry ingestion API.
cmd/gen-docs/main.go Updates docs generator to pass a no-op telemetry service to root.
acceptance/acceptance_test.go Adds telemetry acceptance test suite + disables telemetry by default in shared setup.
acceptance/testdata/telemetry/command-invocation.txtar Acceptance coverage for log-mode command invocation event output.
acceptance/testdata/telemetry/no-telemetry-for-completion.txtar Ensures completion command does not emit telemetry.
acceptance/testdata/telemetry/no-telemetry-for-extension.txtar Ensures extensions do not emit telemetry.
acceptance/testdata/telemetry/no-telemetry-for-send-telemetry.txtar Ensures the sender command does not emit telemetry.
acceptance/testdata/telemetry/telemetry-failure-does-not-break-command.txtar Ensures unreachable endpoint does not break command execution.
go.mod Adds direct dependencies for uuid + twirp used by telemetry implementation.
go.sum Adds checksum entries for new dependencies.
Makefile Adds lint phony target.
.gitignore Ignores test coverage output artifacts.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 36/38 changed files
  • Comments generated: 5

Comment thread internal/telemetry/telemetry.go Outdated
Comment thread internal/telemetry/telemetry.go Outdated
Comment thread pkg/cmd/root/help_topic.go Outdated
Comment thread pkg/cmdutil/telemetry.go
Comment thread internal/ghcmd/cmd.go Outdated
@williammartin williammartin force-pushed the wm/add-telemetry-to-cli branch from ef7f77f to 89a7951 Compare April 17, 2026 09:45
@williammartin williammartin requested review from a team as code owners April 17, 2026 09:45
@williammartin williammartin force-pushed the wm/add-telemetry-to-cli branch from 89a7951 to e83eb09 Compare April 17, 2026 09:50
@williammartin williammartin requested a review from a team April 17, 2026 09:50
@williammartin williammartin force-pushed the wm/add-telemetry-to-cli branch 2 times, most recently from 2a84595 to be6af56 Compare April 17, 2026 10:17
- Harden SpawnSendTelemetry against relative executable paths
- Use io.Copy for telemetry subprocess stdin write
- Clean up GH_TELEMETRY/DO_NOT_TRACK help text
- Fall back to built-in defaults (NoOp telemetry) on config load failure

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@williammartin williammartin force-pushed the wm/add-telemetry-to-cli branch from be6af56 to 17776ca Compare April 17, 2026 10:28
@williammartin williammartin merged commit 73f3900 into trunk Apr 17, 2026
11 checks passed
@williammartin williammartin deleted the wm/add-telemetry-to-cli branch April 17, 2026 12:28
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request May 8, 2026
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [cli/cli](https://github.com/cli/cli) | minor | `v2.90.0` → `v2.92.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>cli/cli (cli/cli)</summary>

### [`v2.92.0`](https://github.com/cli/cli/releases/tag/v2.92.0): GitHub CLI 2.92.0

[Compare Source](cli/cli@v2.91.0...v2.92.0)

#### Support GitHub Enterprise Cloud (GHEC) in `skill` commandset

Now `gh skill` subcommands (`install`, `preview`, `publish`, `search`, `update`) are able to work with [GHEC](https://docs.github.com/en/enterprise-cloud@latest/admin/overview/about-github-enterprise-cloud) hosts with data residency.

#### Add `--allow-hidden-dirs` flag to `skill preview`

Following the addition of `--allow-hidden-dirs` to `skill install` in the previous release, now the flag is also supported in `skill preview`, allowing users to preview skills located in hidden (dot-prefixed) directories such as `.claude/skills/`, `.agents/skills/`, and `.github/skills/`.

#### What's Changed

##### ✨ Features

- feat(skills): add --allow-hidden-dirs flag to preview command by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13265](cli/cli#13265)
- feat(skills): support GHEC with data residency hosts by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13264](cli/cli#13264)

##### 🐛 Fixes

- Fix SetSampleRate not updating sample\_rate dimension by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13259](cli/cli#13259)
- Fix log terminal injection by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13272](cli/cli#13272)
- Add "Resource not accessible" to ProjectsV2IgnorableError by [@&#8203;maxbeizer](https://github.com/maxbeizer) in [#&#8203;13281](cli/cli#13281)

##### 📚 Docs & Chores

- fix: using variable interpolation \`${{ in deployment.yml... by [@&#8203;orbisai0security](https://github.com/orbisai0security) in [#&#8203;13258](cli/cli#13258)
- docs: correct typo in Linux Homebrew copy by [@&#8203;cassidyjames](https://github.com/cassidyjames) in [#&#8203;13273](cli/cli#13273)
- Install skills flat by Name, not namespaced InstallName by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13266](cli/cli#13266)
- chore: fix zsh completion on debian by [@&#8203;babakks](https://github.com/babakks) in [#&#8203;13274](cli/cli#13274)
- Add trust disclaimer to extension help text by [@&#8203;travellertales](https://github.com/travellertales) in [#&#8203;13296](cli/cli#13296)
- Bump Go to 1.26.2 by [@&#8203;github-actions](https://github.com/github-actions)\[bot] in [#&#8203;13301](cli/cli#13301)

##### :dependabot: Dependencies

- chore(deps): bump github.com/mattn/go-isatty from 0.0.20 to 0.0.21 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13161](cli/cli#13161)
- chore(deps): bump github.com/google/go-containerregistry from 0.21.4 to 0.21.5 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13162](cli/cli#13162)
- chore(deps): bump charm.land/lipgloss/v2 from 2.0.2 to 2.0.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13163](cli/cli#13163)
- chore(deps): bump charm.land/bubbletea/v2 from 2.0.2 to 2.0.6 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13206](cli/cli#13206)
- chore(deps): bump github.com/gdamore/tcell/v2 from 2.13.8 to 2.13.9 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13241](cli/cli#13241)
- chore(deps): bump github.com/mattn/go-isatty from 0.0.21 to 0.0.22 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in [#&#8203;13298](cli/cli#13298)

#### New Contributors

- [@&#8203;orbisai0security](https://github.com/orbisai0security) made their first contribution in [#&#8203;13258](cli/cli#13258)
- [@&#8203;cassidyjames](https://github.com/cassidyjames) made their first contribution in [#&#8203;13273](cli/cli#13273)
- [@&#8203;travellertales](https://github.com/travellertales) made their first contribution in [#&#8203;13296](cli/cli#13296)

**Full Changelog**: <cli/cli@v2.91.0...v2.92.0>

### [`v2.91.0`](https://github.com/cli/cli/releases/tag/v2.91.0): GitHub CLI 2.91.0

[Compare Source](cli/cli@v2.90.0...v2.91.0)

#### GitHub CLI now collects pseudonymous telemetry

To better understand how features are used in practice, especially as agentic adoption grows, GitHub CLI now sends pseudonymous telemetry.

See [Telemetry](https://cli.github.com/telemetry) for more details on what's collected, why, and how to opt out.

#### Support more agents in `gh skill`

Thanks to community feedback, `gh` now supports a large number of agent hosts. Run `gh skill install --help` for the list of available agents.

#### Improve skill discovery

`gh skill install` now adds the `--allow-hidden-dirs` flag to support discovering skills in hidden (dot-prefixed) directories such as `.claude/skills/`, `.agents/skills/`, and `.github/skills/`.

#### Detect skills re-published from other sources

GitHut CLI now detects if the skill to be installed is re-published from an upstream source and offers the option to install it from there. The `--upstream` flag is also added for non-interactive use cases.

#### What's Changed

##### ✨ Features

- Add support for installation in multiple agent hosts in `gh skills install` by [@&#8203;tommaso-moro](https://github.com/tommaso-moro) in [#&#8203;13209](cli/cli#13209)
- Add --allow-hidden-dirs flag to gh skill install by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13213](cli/cli#13213)
- Make skill discovery less strict: support nested `skills/` directories by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13235](cli/cli#13235)
- feat(skills): detect re-published skills and offer upstream install by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13236](cli/cli#13236)

##### 🐛 Fixes

- Fix `skills publish --fix` to not publish by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13237](cli/cli#13237)
- fix(skills): match skills by install name in preview command by [@&#8203;SamMorrowDrums](https://github.com/SamMorrowDrums) in [#&#8203;13249](cli/cli#13249)

##### 📚 Docs & Chores

- Remove misleading text by [@&#8203;tommaso-moro](https://github.com/tommaso-moro) in [#&#8203;13203](cli/cli#13203)
- Add sampled command telemetry by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13191](cli/cli#13191)
- Do not send telemetry for aliases by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13192](cli/cli#13192)
- Add skills specific telemetry by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13204](cli/cli#13204)
- Record CI context in telemetry by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13210](cli/cli#13210)
- Record official extension telemetry by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13205](cli/cli#13205)
- Add telemetry command by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13253](cli/cli#13253)
- Log when there is no telemetry by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13255](cli/cli#13255)
- docs(skills): add gh and gh-skill agent skills by [@&#8203;BagToad](https://github.com/BagToad) in [#&#8203;13244](cli/cli#13244)
- Enable telemetry without env var by [@&#8203;williammartin](https://github.com/williammartin) in [#&#8203;13254](cli/cli#13254)

**Full Changelog**: <cli/cli@v2.90.0...v2.91.0>

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Mend Renovate](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNjkuNCIsInVwZGF0ZWRJblZlciI6IjQzLjE2OS40IiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiLCJhdXRvbWF0aW9uOmJvdC1hdXRob3JlZCIsImRlcGVuZGVuY3ktdHlwZTo6bWlub3IiXX0=-->
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.

4 participants