feat(core): include surface identifier in User-Agent header#21934
feat(core): include surface identifier in User-Agent header#21934SandyTao520 wants to merge 1 commit intomainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the Gemini CLI's ability to identify its operating environment by including a "surface" identifier in the Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
471ab86 to
c210602
Compare
There was a problem hiding this comment.
Code Review
This pull request is a great improvement, adding the surface identifier to the User-Agent header for better request tracking and refactoring the detection logic into a shared utility. The implementation is clean and well-tested. I found one high-severity issue with the surface detection logic. The current implementation is too restrictive and fails to detect several supported IDEs (like Sublime Text, JetBrains, Replit), leading to incorrect telemetry and User-Agent data. I've suggested a fix to make the detection more comprehensive and robust.
|
Size Change: +300 B (0%) Total Size: 26.5 MB ℹ️ View Unchanged
|
c210602 to
99f522c
Compare
Add the detected surface/IDE (e.g., vscode, cursor, terminal) to the User-Agent string sent with API requests. This allows enterprise customers to distinguish traffic from different clients (e.g., GCA Agent Mode vs standalone CLI) in their GCP logs. The surface is determined by a new shared utility that checks: 1. GEMINI_CLI_SURFACE env var (first-class enterprise override) 2. SURFACE env var (legacy, backward-compatible) 3. Auto-detection via existing detectIdeFromEnv() The clearcut-logger telemetry is also updated to use this shared utility, gaining GEMINI_CLI_SURFACE support. Closes #18007
99f522c to
ece9941
Compare
Summary
Include the detected surface/IDE identifier (e.g.,
vscode,cursor,terminal) in theUser-AgentHTTP header sent with Gemini API requests. This enables enterprise customers to distinguish traffic originating from different clients (e.g., GCA VSCode Agent Mode vs standalone CLI) in their GCP Cloud Logging/Monitoring dashboards.Details
Problem: The CLI's User-Agent (
GeminiCLI/{version}/{model} ({platform}; {arch})) doesn't identify the source environment. Enterprise customers cannot tell whether a request came from VSCode Agent Mode, standalone CLI, Cursor, or any other embedding.Solution: Append the surface identifier to the User-Agent parenthetical:
Implementation:
New shared utility (
packages/core/src/utils/surface.ts):determineSurface()with priority:GEMINI_CLI_SURFACEenv var — first-class override for enterprise customersSURFACEenv var — legacy, backward-compatibledetectIdeFromEnv()(supports ~15+ IDEs)SURFACE_NOT_SETcontentGenerator.ts: User-Agent now includes the surface identifierclearcut-logger.ts: Refactored to use the shared utility (also gainsGEMINI_CLI_SURFACEsupport; existing telemetry values preserved)Enterprise usage:
Related Issues
Closes #18007
How to Validate
Run the new surface utility tests:
npm test -w @google/gemini-cli-core -- src/utils/surface.test.tsRun content generator tests (includes new User-Agent surface tests):
npm test -w @google/gemini-cli-core -- src/core/contentGenerator.test.tsRun clearcut-logger tests (includes GEMINI_CLI_SURFACE test cases):
npm test -w @google/gemini-cli-core -- src/telemetry/clearcut-logger/clearcut-logger.test.tsManual verification:
Pre-Merge Checklist