mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-10 14:10:37 -07:00
Telemtry(extensions) - Add logging for extension events (#8339)
Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
@@ -307,6 +307,15 @@ for Gemini CLI:
|
||||
- `command` (string)
|
||||
- `subcommand` (string, if applicable)
|
||||
|
||||
- `gemini_cli.extension_enable`: This event occurs when an extension is enabled
|
||||
- `gemini_cli.extension_install`: This event occurs when an extension is installed
|
||||
- **Attributes**:
|
||||
- `extension_name` (string)
|
||||
- `extension_version` (string)
|
||||
- `extension_source` (string)
|
||||
- `status` (string)
|
||||
- `gemini_cli.extension_uninstall`: This event occurs when an extension is uninstalled
|
||||
|
||||
### Metrics
|
||||
|
||||
Metrics are numerical measurements of behavior over time. The following metrics are collected for Gemini CLI:
|
||||
|
||||
@@ -24,9 +24,8 @@ import {
|
||||
import {
|
||||
GEMINI_DIR,
|
||||
type GeminiCLIExtension,
|
||||
ClearcutLogger,
|
||||
type Config,
|
||||
ExtensionUninstallEvent,
|
||||
ExtensionEnableEvent,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { execSync } from 'node:child_process';
|
||||
import { SettingScope } from './settings.js';
|
||||
@@ -69,20 +68,18 @@ vi.mock('./trustedFolders.js', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
const mockLogExtensionEnable = vi.hoisted(() => vi.fn());
|
||||
const mockLogExtensionInstallEvent = vi.hoisted(() => vi.fn());
|
||||
const mockLogExtensionUninstall = vi.hoisted(() => vi.fn());
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
||||
const mockLogExtensionInstallEvent = vi.fn();
|
||||
const mockLogExtensionUninstallEvent = vi.fn();
|
||||
return {
|
||||
...actual,
|
||||
ClearcutLogger: {
|
||||
getInstance: vi.fn(() => ({
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstallEvent: mockLogExtensionUninstallEvent,
|
||||
})),
|
||||
},
|
||||
Config: vi.fn(),
|
||||
logExtensionEnable: mockLogExtensionEnable,
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstall: mockLogExtensionUninstall,
|
||||
ExtensionEnableEvent: vi.fn(),
|
||||
ExtensionInstallEvent: vi.fn(),
|
||||
ExtensionUninstallEvent: vi.fn(),
|
||||
};
|
||||
@@ -763,8 +760,7 @@ describe('extension tests', () => {
|
||||
|
||||
await installExtension({ source: sourceExtDir, type: 'local' });
|
||||
|
||||
const logger = ClearcutLogger.getInstance({} as Config);
|
||||
expect(logger?.logExtensionInstallEvent).toHaveBeenCalled();
|
||||
expect(mockLogExtensionInstallEvent).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should show users information on their mcp server when installing', async () => {
|
||||
@@ -948,9 +944,10 @@ describe('extension tests', () => {
|
||||
|
||||
await uninstallExtension('my-local-extension');
|
||||
|
||||
const logger = ClearcutLogger.getInstance({} as Config);
|
||||
expect(logger?.logExtensionUninstallEvent).toHaveBeenCalledWith(
|
||||
new ExtensionUninstallEvent('my-local-extension', 'success'),
|
||||
expect(mockLogExtensionUninstall).toHaveBeenCalled();
|
||||
expect(ExtensionUninstallEvent).toHaveBeenCalledWith(
|
||||
'my-local-extension',
|
||||
'success',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -969,9 +966,10 @@ describe('extension tests', () => {
|
||||
await uninstallExtension(gitUrl);
|
||||
|
||||
expect(fs.existsSync(sourceExtDir)).toBe(false);
|
||||
const logger = ClearcutLogger.getInstance({} as Config);
|
||||
expect(logger?.logExtensionUninstallEvent).toHaveBeenCalledWith(
|
||||
new ExtensionUninstallEvent('gemini-sql-extension', 'success'),
|
||||
expect(mockLogExtensionUninstall).toHaveBeenCalled();
|
||||
expect(ExtensionUninstallEvent).toHaveBeenCalledWith(
|
||||
'gemini-sql-extension',
|
||||
'success',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1233,6 +1231,22 @@ describe('extension tests', () => {
|
||||
expect(activeExtensions).toHaveLength(1);
|
||||
expect(activeExtensions[0].name).toBe('ext1');
|
||||
});
|
||||
|
||||
it('should log an enable event', () => {
|
||||
createExtension({
|
||||
extensionsDir: userExtensionsDir,
|
||||
name: 'ext1',
|
||||
version: '1.0.0',
|
||||
});
|
||||
disableExtension('ext1', SettingScope.Workspace);
|
||||
enableExtension('ext1', SettingScope.Workspace);
|
||||
|
||||
expect(mockLogExtensionEnable).toHaveBeenCalled();
|
||||
expect(ExtensionEnableEvent).toHaveBeenCalledWith(
|
||||
'ext1',
|
||||
SettingScope.Workspace,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -12,10 +12,13 @@ import type {
|
||||
import {
|
||||
GEMINI_DIR,
|
||||
Storage,
|
||||
ClearcutLogger,
|
||||
Config,
|
||||
ExtensionInstallEvent,
|
||||
ExtensionUninstallEvent,
|
||||
ExtensionEnableEvent,
|
||||
logExtensionEnable,
|
||||
logExtensionInstallEvent,
|
||||
logExtensionUninstall,
|
||||
} from '@google/gemini-cli-core';
|
||||
import * as fs from 'node:fs';
|
||||
import * as path from 'node:path';
|
||||
@@ -123,16 +126,18 @@ export async function performWorkspaceExtensionMigration(
|
||||
return failedInstallNames;
|
||||
}
|
||||
|
||||
function getClearcutLogger(cwd: string) {
|
||||
function getTelemetryConfig(cwd: string) {
|
||||
const settings = loadSettings(cwd);
|
||||
const config = new Config({
|
||||
telemetry: settings.merged.telemetry,
|
||||
interactive: false,
|
||||
sessionId: randomUUID(),
|
||||
targetDir: cwd,
|
||||
cwd,
|
||||
model: '',
|
||||
debugMode: false,
|
||||
});
|
||||
const logger = ClearcutLogger.getInstance(config);
|
||||
return logger;
|
||||
return config;
|
||||
}
|
||||
|
||||
export function loadExtensions(
|
||||
@@ -372,7 +377,7 @@ export async function installExtension(
|
||||
askConsent: boolean = false,
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<string> {
|
||||
const logger = getClearcutLogger(cwd);
|
||||
const telemetryConfig = getTelemetryConfig(cwd);
|
||||
let newExtensionConfig: ExtensionConfig | null = null;
|
||||
let localSourcePath: string | undefined;
|
||||
|
||||
@@ -467,7 +472,8 @@ export async function installExtension(
|
||||
}
|
||||
}
|
||||
|
||||
logger?.logExtensionInstallEvent(
|
||||
logExtensionInstallEvent(
|
||||
telemetryConfig,
|
||||
new ExtensionInstallEvent(
|
||||
newExtensionConfig!.name,
|
||||
newExtensionConfig!.version,
|
||||
@@ -491,7 +497,8 @@ export async function installExtension(
|
||||
// Ignore error, this is just for logging.
|
||||
}
|
||||
}
|
||||
logger?.logExtensionInstallEvent(
|
||||
logExtensionInstallEvent(
|
||||
telemetryConfig,
|
||||
new ExtensionInstallEvent(
|
||||
newExtensionConfig?.name ?? '',
|
||||
newExtensionConfig?.version ?? '',
|
||||
@@ -559,7 +566,7 @@ export async function uninstallExtension(
|
||||
extensionIdentifier: string,
|
||||
cwd: string = process.cwd(),
|
||||
): Promise<void> {
|
||||
const logger = getClearcutLogger(cwd);
|
||||
const telemetryConfig = getTelemetryConfig(cwd);
|
||||
const installedExtensions = loadUserExtensions();
|
||||
const extensionName = installedExtensions.find(
|
||||
(installed) =>
|
||||
@@ -581,7 +588,8 @@ export async function uninstallExtension(
|
||||
recursive: true,
|
||||
force: true,
|
||||
});
|
||||
logger?.logExtensionUninstallEvent(
|
||||
logExtensionUninstall(
|
||||
telemetryConfig,
|
||||
new ExtensionUninstallEvent(extensionName, 'success'),
|
||||
);
|
||||
}
|
||||
@@ -648,4 +656,6 @@ export function enableExtension(
|
||||
);
|
||||
const scopePath = scope === SettingScope.Workspace ? cwd : os.homedir();
|
||||
manager.enable(name, true, scopePath);
|
||||
const config = getTelemetryConfig(cwd);
|
||||
logExtensionEnable(config, new ExtensionEnableEvent(name, scope));
|
||||
}
|
||||
|
||||
@@ -55,20 +55,16 @@ vi.mock('../trustedFolders.js', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
const mockLogExtensionInstallEvent = vi.hoisted(() => vi.fn());
|
||||
const mockLogExtensionUninstall = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
||||
const mockLogExtensionInstallEvent = vi.fn();
|
||||
const mockLogExtensionUninstallEvent = vi.fn();
|
||||
return {
|
||||
...actual,
|
||||
ClearcutLogger: {
|
||||
getInstance: vi.fn(() => ({
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstallEvent: mockLogExtensionUninstallEvent,
|
||||
})),
|
||||
},
|
||||
Config: vi.fn(),
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstall: mockLogExtensionUninstall,
|
||||
ExtensionInstallEvent: vi.fn(),
|
||||
ExtensionUninstallEvent: vi.fn(),
|
||||
};
|
||||
|
||||
@@ -56,20 +56,16 @@ vi.mock('../../config/trustedFolders.js', async (importOriginal) => {
|
||||
};
|
||||
});
|
||||
|
||||
const mockLogExtensionInstallEvent = vi.hoisted(() => vi.fn());
|
||||
const mockLogExtensionUninstall = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock('@google/gemini-cli-core', async (importOriginal) => {
|
||||
const actual =
|
||||
await importOriginal<typeof import('@google/gemini-cli-core')>();
|
||||
const mockLogExtensionInstallEvent = vi.fn();
|
||||
const mockLogExtensionUninstallEvent = vi.fn();
|
||||
return {
|
||||
...actual,
|
||||
ClearcutLogger: {
|
||||
getInstance: vi.fn(() => ({
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstallEvent: mockLogExtensionUninstallEvent,
|
||||
})),
|
||||
},
|
||||
Config: vi.fn(),
|
||||
logExtensionInstallEvent: mockLogExtensionInstallEvent,
|
||||
logExtensionUninstall: mockLogExtensionUninstall,
|
||||
ExtensionInstallEvent: vi.fn(),
|
||||
ExtensionUninstallEvent: vi.fn(),
|
||||
};
|
||||
|
||||
@@ -24,12 +24,16 @@ export {
|
||||
DEFAULT_TRUNCATE_TOOL_OUTPUT_THRESHOLD,
|
||||
} from './src/config/config.js';
|
||||
export { detectIdeFromEnv } from './src/ide/detect-ide.js';
|
||||
export { logIdeConnection } from './src/telemetry/loggers.js';
|
||||
export {
|
||||
logExtensionEnable,
|
||||
logIdeConnection,
|
||||
} from './src/telemetry/loggers.js';
|
||||
|
||||
export {
|
||||
IdeConnectionEvent,
|
||||
IdeConnectionType,
|
||||
ExtensionInstallEvent,
|
||||
ExtensionEnableEvent,
|
||||
ExtensionUninstallEvent,
|
||||
} from './src/telemetry/types.js';
|
||||
export { makeFakeConfig } from './src/test-utils/config.js';
|
||||
|
||||
@@ -24,11 +24,11 @@ import type {
|
||||
InvalidChunkEvent,
|
||||
ContentRetryEvent,
|
||||
ContentRetryFailureEvent,
|
||||
ExtensionEnableEvent,
|
||||
ExtensionInstallEvent,
|
||||
ToolOutputTruncatedEvent,
|
||||
ExtensionUninstallEvent,
|
||||
ModelRoutingEvent,
|
||||
ExtensionEnableEvent,
|
||||
} from '../types.js';
|
||||
import { EventMetadataKey } from './event-metadata-key.js';
|
||||
import type { Config } from '../../config/config.js';
|
||||
|
||||
@@ -36,6 +36,9 @@ export {
|
||||
logKittySequenceOverflow,
|
||||
logChatCompression,
|
||||
logToolOutputTruncated,
|
||||
logExtensionEnable,
|
||||
logExtensionInstallEvent,
|
||||
logExtensionUninstall,
|
||||
} from './loggers.js';
|
||||
export type { SlashCommandEvent, ChatCompressionEvent } from './types.js';
|
||||
export {
|
||||
|
||||
Reference in New Issue
Block a user