feat(telemetry): add specific PR, issue, and custom tracking IDs for GitHub Actions#21129
Open
cocosheng-g wants to merge 6 commits intogoogle-gemini:mainfrom
Open
feat(telemetry): add specific PR, issue, and custom tracking IDs for GitHub Actions#21129cocosheng-g wants to merge 6 commits intogoogle-gemini:mainfrom
cocosheng-g wants to merge 6 commits intogoogle-gemini:mainfrom
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
…ng env before setup
a8541db to
7a621a9
Compare
…, issue, and custom tracking ids - Replaced `GEMINI_CLI_GH_EVENT_NUMBER` with `GEMINI_CLI_GH_PR_NUMBER`, `GEMINI_CLI_GH_ISSUE_NUMBER`, and `GEMINI_CLI_GH_CUSTOM_TRACKING_ID` to allow tracking of specific GitHub Action contexts. - Updated `ClearcutLogger` to extract `GH_PR_NUMBER`, `GH_ISSUE_NUMBER`, and `GH_CUSTOM_TRACKING_ID` from the environment. - Updated telemetry unit tests to verify the new environment variables and metadata keys. - Updated telemetry documentation in `docs/cli/telemetry.md` to reflect the new attributes.
7a621a9 to
8fcf4c2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
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).
Will fix #21130
Details
GEMINI_CLI_GH_EVENT_NAMEtoEventMetadataKey.GEMINI_CLI_GH_PR_NUMBER,GEMINI_CLI_GH_ISSUE_NUMBER, andGEMINI_CLI_GH_CUSTOM_TRACKING_IDreplacing genericGH_EVENT_NUMBER.ClearcutLoggerto capture these from environment variables (GITHUB_EVENT_NAME,GH_PR_NUMBER,GH_ISSUE_NUMBER, andGH_CUSTOM_TRACKING_ID).123) to avoid fingerprinting PII, relying on the repository context to provide global uniqueness for backend queries.clearcut-logger.test.tsto cover the new environment variables and metadata keys.docs/cli/telemetry.md.Related Issues
Related to internal PM request for "Gemini CLI GitHub Action Usage Metric".
How to Validate
npm test -w @google/gemini-cli-core -- src/telemetry/clearcut-logger/clearcut-logger.test.tsGITHUB_EVENT_NAMEand specific IDs (GH_PR_NUMBER, etc.) are set in the environment, they appear in the Clearcut log metadata as expected.Example events
Sample 1: api_request (Automated Issue Triage)
Triggered when the CLI sends a prompt to the model during an "Issue Opened" event.
{ "event_name": "api_request", "console_type": "GEMINI_CLI", "application": 102, "event_metadata": [ [ { "gemini_cli_key": 20, "value": "gemini-1.5-pro" }, // API_REQUEST_MODEL { "gemini_cli_key": 39, "value": "GitHub" }, // SURFACE { "gemini_cli_key": 130, "value": "gemini-triage" }, // GH_WORKFLOW_NAME { "gemini_cli_key": 132, "value": "a1b2c3d4..." }, // GH_REPO_HASH { "gemini_cli_key": 176, "value": "issues" }, // GH_EVENT_NAME { "gemini_cli_key": 178, "value": "42" } // GH_ISSUE_NUMBER (Issue #42) ] ] }Sample 2: api_response (PR Review)
Triggered when the model returns a response for a Pull Request review.
{ "event_name": "api_response", "console_type": "GEMINI_CLI", "application": 102, "event_metadata": [ [ { "gemini_cli_key": 21, "value": "gemini-1.5-pro" }, // API_RESPONSE_MODEL { "gemini_cli_key": 25, "value": "1240" }, // INPUT_TOKEN_COUNT { "gemini_cli_key": 26, "value": "450" }, // OUTPUT_TOKEN_COUNT { "gemini_cli_key": 130, "value": "gemini-review" }, // GH_WORKFLOW_NAME { "gemini_cli_key": 176, "value": "pull_request" }, // GH_EVENT_NAME { "gemini_cli_key": 177, "value": "101" } // GH_PR_NUMBER (PR #101) ] ] }Sample 3: start_session (Scheduled Triage)
Triggered when the CLI starts up as part of a cron job (Scheduled).
{ "event_name": "start_session", "console_type": "GEMINI_CLI", "application": 102, "event_metadata": [ [ { "gemini_cli_key": 1, "value": "gemini-1.5-flash" }, // START_SESSION_MODEL { "gemini_cli_key": 130, "value": "gemini-issue-fixer" }, // GH_WORKFLOW_NAME { "gemini_cli_key": 176, "value": "schedule" }, // GH_EVENT_NAME { "gemini_cli_key": 179, "value": "101,102,103" } // GH_CUSTOM_TRACKING_ID ] ] }Pre-Merge Checklist