mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 22:21:22 -07:00
fix(telemetry): Improve Cloud Shell surface type detection for telemetry purposes (#10162)
This commit is contained in:
@@ -21,6 +21,10 @@ export interface IdeInfo {
|
||||
displayName: string;
|
||||
}
|
||||
|
||||
export function isCloudShell(): boolean {
|
||||
return !!(process.env['EDITOR_IN_CLOUD_SHELL'] || process.env['CLOUD_SHELL']);
|
||||
}
|
||||
|
||||
export function detectIdeFromEnv(): IdeInfo {
|
||||
if (process.env['__COG_BASHRC_SOURCED']) {
|
||||
return IDE_DEFINITIONS.devin;
|
||||
@@ -34,7 +38,7 @@ export function detectIdeFromEnv(): IdeInfo {
|
||||
if (process.env['CODESPACES']) {
|
||||
return IDE_DEFINITIONS.codespaces;
|
||||
}
|
||||
if (process.env['EDITOR_IN_CLOUD_SHELL'] || process.env['CLOUD_SHELL']) {
|
||||
if (isCloudShell()) {
|
||||
return IDE_DEFINITIONS.cloudshell;
|
||||
}
|
||||
if (process.env['TERM_PRODUCT'] === 'Trae') {
|
||||
|
||||
@@ -221,6 +221,32 @@ describe('ClearcutLogger', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('logs the current surface from Cloud Shell via EDITOR_IN_CLOUD_SHELL', () => {
|
||||
const { logger } = setup({});
|
||||
|
||||
vi.stubEnv('EDITOR_IN_CLOUD_SHELL', 'true');
|
||||
|
||||
const event = logger?.createLogEvent(EventNames.CHAT_COMPRESSION, []);
|
||||
|
||||
expect(event?.event_metadata[0]).toContainEqual({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
|
||||
value: 'cloudshell',
|
||||
});
|
||||
});
|
||||
|
||||
it('logs the current surface from Cloud Shell via CLOUD_SHELL', () => {
|
||||
const { logger } = setup({});
|
||||
|
||||
vi.stubEnv('CLOUD_SHELL', 'true');
|
||||
|
||||
const event = logger?.createLogEvent(EventNames.CHAT_COMPRESSION, []);
|
||||
|
||||
expect(event?.event_metadata[0]).toContainEqual({
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE,
|
||||
value: 'cloudshell',
|
||||
});
|
||||
});
|
||||
|
||||
it('logs default metadata', () => {
|
||||
// Define expected values
|
||||
const session_id = 'my-session-id';
|
||||
|
||||
@@ -39,7 +39,11 @@ import { UserAccountManager } from '../../utils/userAccountManager.js';
|
||||
import { safeJsonStringify } from '../../utils/safeJsonStringify.js';
|
||||
import { FixedDeque } from 'mnemonist';
|
||||
import { GIT_COMMIT_INFO, CLI_VERSION } from '../../generated/git-commit.js';
|
||||
import { IDE_DEFINITIONS, detectIdeFromEnv } from '../../ide/detect-ide.js';
|
||||
import {
|
||||
IDE_DEFINITIONS,
|
||||
detectIdeFromEnv,
|
||||
isCloudShell,
|
||||
} from '../../ide/detect-ide.js';
|
||||
|
||||
export enum EventNames {
|
||||
START_SESSION = 'start_session',
|
||||
@@ -114,6 +118,8 @@ export interface LogRequest {
|
||||
function determineSurface(): string {
|
||||
if (process.env['SURFACE']) {
|
||||
return process.env['SURFACE'];
|
||||
} else if (isCloudShell()) {
|
||||
return IDE_DEFINITIONS.cloudshell.name;
|
||||
} else if (process.env['GITHUB_SHA']) {
|
||||
return 'GitHub';
|
||||
} else if (process.env['TERM_PROGRAM'] === 'vscode') {
|
||||
|
||||
Reference in New Issue
Block a user