|
| 1 | +## Summary |
| 2 | + |
| 3 | +This PR adds new telemetry attributes to the Gemini CLI to support granular usage metrics for GitHub Actions. These metrics will allow us to track unique Issues and PRs touched by the CLI, and distinguish between different workflow triggers (e.g., Automated vs. Scheduled triage). |
| 4 | + |
| 5 | +Will fix https://github.com/google-gemini/gemini-cli/issues/21130 |
| 6 | + |
| 7 | +## Details |
| 8 | + |
| 9 | +- Added `GEMINI_CLI_GH_EVENT_NAME` to `EventMetadataKey`. |
| 10 | +- Added specific tracking IDs: `GEMINI_CLI_GH_PR_NUMBER`, `GEMINI_CLI_GH_ISSUE_NUMBER`, and `GEMINI_CLI_GH_CUSTOM_TRACKING_ID` replacing generic `GH_EVENT_NUMBER`. |
| 11 | +- Updated `ClearcutLogger` to capture these from environment variables (`GITHUB_EVENT_NAME`, `GH_PR_NUMBER`, `GH_ISSUE_NUMBER`, and `GH_CUSTOM_TRACKING_ID`). |
| 12 | +- The PR/Issue number is logged as a raw string ID (e.g., `123`) to avoid fingerprinting PII, relying on the repository context to provide global uniqueness for backend queries. |
| 13 | +- Updated telemetry tests in `clearcut-logger.test.ts` to cover the new environment variables and metadata keys. |
| 14 | +- Updated telemetry documentation in `docs/cli/telemetry.md`. |
| 15 | + |
| 16 | +### Example Telemetry Scenarios |
| 17 | + |
| 18 | +Because the CLI appends these context fields to the `baseMetadata` of all events (API Request, Response, Error), downstream analytics can perfectly distinguish and count unique issues vs. PRs based on the workflow context. |
| 19 | + |
| 20 | +#### Scenario A: Automated PR Review |
| 21 | + |
| 22 | +When PR #42 triggers the `gemini-review` workflow, the CLI logs: |
| 23 | + |
| 24 | +```json |
| 25 | +{ |
| 26 | + "event_name": "api_request", |
| 27 | + "event_metadata": [ |
| 28 | + [ |
| 29 | + { "gemini_cli_key": 130, "value": "gemini-review" }, |
| 30 | + { "gemini_cli_key": 172, "value": "pull_request" }, |
| 31 | + { "gemini_cli_key": 173, "value": "42" } // GH_PR_NUMBER |
| 32 | + ] |
| 33 | + ] |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +_Analysts can count `DISTINCT gh_pr_number WHERE gh_workflow_name LIKE '%review%'` to satisfy the P0 PR metric._ |
| 38 | + |
| 39 | +#### Scenario B: Automated Issue Triage |
| 40 | + |
| 41 | +When Issue #88 triggers the `gemini-triage` workflow, the CLI logs: |
| 42 | + |
| 43 | +```json |
| 44 | +{ |
| 45 | + "event_name": "api_request", |
| 46 | + "event_metadata": [ |
| 47 | + [ |
| 48 | + { "gemini_cli_key": 130, "value": "gemini-triage" }, |
| 49 | + { "gemini_cli_key": 172, "value": "issues" }, |
| 50 | + { "gemini_cli_key": 174, "value": "88" } // GH_ISSUE_NUMBER |
| 51 | + ] |
| 52 | + ] |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +_Analysts can count `DISTINCT gh_issue_number WHERE gh_workflow_name LIKE '%triage%' AND gh_event_name = 'issues'` to satisfy the P0 Automated Issue metric._ |
| 57 | + |
| 58 | +#### Scenario C: Scheduled Batch Triage |
| 59 | + |
| 60 | +When a cron job runs and triages 3 issues (IDs 101, 102, 103) in a single CLI invocation, the CLI logs: |
| 61 | + |
| 62 | +```json |
| 63 | +{ |
| 64 | + "event_name": "api_request", |
| 65 | + "event_metadata": [ |
| 66 | + [ |
| 67 | + { "gemini_cli_key": 130, "value": "gemini-scheduled-triage" }, |
| 68 | + { "gemini_cli_key": 172, "value": "schedule" }, |
| 69 | + { "gemini_cli_key": 175, "value": "101,102,103" } // GH_CUSTOM_TRACKING_ID |
| 70 | + ] |
| 71 | + ] |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +_Analysts can split the `gh_custom_tracking_id` string by commas to count exactly 3 unique issues processed during a scheduled invocation._ |
| 76 | + |
| 77 | +## Related Issues |
| 78 | + |
| 79 | +Related to internal PM request for "Gemini CLI GitHub Action Usage Metric". |
| 80 | + |
| 81 | +## How to Validate |
| 82 | + |
| 83 | +1. Run the new tests: `npm test -w @google/gemini-cli-core -- src/telemetry/clearcut-logger/clearcut-logger.test.ts` |
| 84 | +2. Verify that when `GITHUB_EVENT_NAME` and specific IDs (`GH_PR_NUMBER`, etc.) are set in the environment, they appear in the Clearcut log metadata as expected. |
| 85 | + |
| 86 | +## Pre-Merge Checklist |
| 87 | + |
| 88 | +- [x] Updated relevant documentation and README (if needed) |
| 89 | +- [x] Added/updated tests (if needed) |
| 90 | +- [ ] Noted breaking changes (if any) |
| 91 | +- [ ] Validated on required platforms/methods: |
| 92 | + - [ ] MacOS |
| 93 | + - [ ] Windows |
| 94 | + - [x] Linux |
0 commit comments