Skip to content

feat(ENG-15367): capture usage facts and send one event at the end of every run - #571

Open
tigh-latte wants to merge 1 commit into
eng-14331-3-senderfrom
eng-14331-4-capture
Open

tigh-latte wants to merge 1 commit into
eng-14331-3-senderfrom
eng-14331-4-capture

Conversation

@tigh-latte

@tigh-latte tigh-latte commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Usage telemetry stack, part 4 of 9. Builds on #570. Next: #572.

Description

This PR wires usage telemetry into the CLI. A hook on the root command records facts from the Click context, and AliasGroup.main hands them to the sender from #570 when the run ends. New commands and flags show up in telemetry with no telemetry code.

  • usage_capture.py records the command path, parameter names and where each value came from, the typed flag spellings and aliases, the login method and the API status. It records names defined in code only, never values. Grouped short options (-vS, -vPname) are split up as Click does, so a typed -S or -P always reaches the send checks.
  • config_sources.py reports which config or credentials file and profile set a setting, by setting name only.
  • handle_api_exceptions records the HTTP status of a handled API error.
  • The credential helper commands and login now use the tracked command classes, so their runs are recorded or excluded the same way as every other command.

Behaviour changes

How to try it

CLOUDSMITH_TELEMETRY=log CLOUDSMITH_TELEMETRY_POSTHOG_KEY=phc_dummy cloudsmith --version
Output on stderr
[telemetry] would send (log mode, nothing sent):
{
  "distinct_id": "31b023d1-966a-4fb2-a60d-3e17af367674",
  "event": "cli command executed",
  "properties": {
    "$geoip_disable": true,
    "$process_person_profile": false,
    "aliases_used": [],
    "arch": "arm64",
    "channel": "uv-pip",
    "ci": false,
    "cli_version": "1.30.0",
    "command": "<root>",
    "duration_ms": 207,
    "environment": "development",
    "envvars": [],
    "exit_code": 0,
    "first_run": true,
    "flags": [
      "version"
    ],
    "flags_typed": [
      "--version"
    ],
    "install_id_persisted": true,
    "os": "Darwin",
    "os_version": "25.6",
    "outcome": "success",
    "output_format": "pretty",
    "persona": "human",
    "python_version": "3.14",
    "sample_rate": 100,
    "schema_version": 1,
    "stdout_tty": false
  },
  "timestamp": "2026-10-26T11:56:11.787694+00:00"
}

outcome is one of success, help, usage_error, click_error, api_error, error_exit, aborted or unexpected_error. exit_code is the raw value the process exits with today.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Refactoring
  • Other (please describe)

Additional Notes

N/A: there are no user-facing changes while no project key is set.

🤖 Generated with Claude Code

@tigh-latte tigh-latte changed the title feat(ENG-14331): capture usage facts and send one event at the end of every run feat(ENG-15367): capture usage facts and send one event at the end of every run Oct 29, 2026
@tigh-latte
tigh-latte force-pushed the eng-14331-3-sender branch 2 times, most recently from 221d096 to a62e7b9 Compare November 3, 2026 13:58
@tigh-latte
tigh-latte marked this pull request as ready for review November 4, 2026 10:15
@tigh-latte
tigh-latte requested a review from a team as a code owner November 4, 2026 10:15
… every run

A hook on the root command records the command path, the flags and
aliases used, where each setting came from, the login method and the API
status, all from the Click context, so new commands and flags need no
telemetry code. AliasGroup.main hands the run to the sender when it ends.

Credential helper commands and login use the tracked command classes so
their runs are recorded (or excluded) consistently.

Grouped short options (-vS, -vPname) are split up as Click does, so a
typed -S or -P always reaches the send rules. The reported env var is
the first non-empty one, as Click uses, and a typed --help only counts
as help when the run succeeded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants