mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 02:24:09 -07:00
fix(telemetry): Prevent duplicate StartSessionEvent logging (#12090)
This commit is contained in:
@@ -10,6 +10,8 @@ import {
|
|||||||
IdeConnectionType,
|
IdeConnectionType,
|
||||||
logIdeConnection,
|
logIdeConnection,
|
||||||
type Config,
|
type Config,
|
||||||
|
StartSessionEvent,
|
||||||
|
logCliConfiguration,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import { type LoadedSettings } from '../config/settings.js';
|
import { type LoadedSettings } from '../config/settings.js';
|
||||||
import { performInitialAuth } from './auth.js';
|
import { performInitialAuth } from './auth.js';
|
||||||
@@ -42,6 +44,11 @@ export async function initializeApp(
|
|||||||
const shouldOpenAuthDialog =
|
const shouldOpenAuthDialog =
|
||||||
settings.merged.security?.auth?.selectedType === undefined || !!authError;
|
settings.merged.security?.auth?.selectedType === undefined || !!authError;
|
||||||
|
|
||||||
|
logCliConfiguration(
|
||||||
|
config,
|
||||||
|
new StartSessionEvent(config, config.getToolRegistry()),
|
||||||
|
);
|
||||||
|
|
||||||
if (config.getIdeMode()) {
|
if (config.getIdeMode()) {
|
||||||
const ideClient = await IdeClient.getInstance();
|
const ideClient = await IdeClient.getInstance();
|
||||||
await ideClient.connect();
|
await ideClient.connect();
|
||||||
|
|||||||
@@ -174,6 +174,18 @@ describe('gemini.tsx main function', () => {
|
|||||||
getMessageBus: () => ({
|
getMessageBus: () => ({
|
||||||
subscribe: vi.fn(),
|
subscribe: vi.fn(),
|
||||||
}),
|
}),
|
||||||
|
getToolRegistry: vi.fn(),
|
||||||
|
getContentGeneratorConfig: vi.fn(),
|
||||||
|
getModel: () => 'gemini-pro',
|
||||||
|
getEmbeddingModel: () => 'embedding-001',
|
||||||
|
getApprovalMode: () => 'default',
|
||||||
|
getCoreTools: () => [],
|
||||||
|
getTelemetryEnabled: () => false,
|
||||||
|
getTelemetryLogPromptsEnabled: () => false,
|
||||||
|
getFileFilteringRespectGitIgnore: () => true,
|
||||||
|
getOutputFormat: () => 'text',
|
||||||
|
getExtensions: () => [],
|
||||||
|
getUsageStatisticsEnabled: () => false,
|
||||||
} as unknown as Config;
|
} as unknown as Config;
|
||||||
});
|
});
|
||||||
vi.mocked(loadSettings).mockReturnValue({
|
vi.mocked(loadSettings).mockReturnValue({
|
||||||
@@ -309,6 +321,18 @@ describe('gemini.tsx main function kitty protocol', () => {
|
|||||||
getMessageBus: () => ({
|
getMessageBus: () => ({
|
||||||
subscribe: vi.fn(),
|
subscribe: vi.fn(),
|
||||||
}),
|
}),
|
||||||
|
getToolRegistry: vi.fn(),
|
||||||
|
getContentGeneratorConfig: vi.fn(),
|
||||||
|
getModel: () => 'gemini-pro',
|
||||||
|
getEmbeddingModel: () => 'embedding-001',
|
||||||
|
getApprovalMode: () => 'default',
|
||||||
|
getCoreTools: () => [],
|
||||||
|
getTelemetryEnabled: () => false,
|
||||||
|
getTelemetryLogPromptsEnabled: () => false,
|
||||||
|
getFileFilteringRespectGitIgnore: () => true,
|
||||||
|
getOutputFormat: () => 'text',
|
||||||
|
getExtensions: () => [],
|
||||||
|
getUsageStatisticsEnabled: () => false,
|
||||||
} as unknown as Config);
|
} as unknown as Config);
|
||||||
vi.mocked(loadSettings).mockReturnValue({
|
vi.mocked(loadSettings).mockReturnValue({
|
||||||
errors: [],
|
errors: [],
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import {
|
|||||||
} from '../core/contentGenerator.js';
|
} from '../core/contentGenerator.js';
|
||||||
import { GeminiClient } from '../core/client.js';
|
import { GeminiClient } from '../core/client.js';
|
||||||
import { GitService } from '../services/gitService.js';
|
import { GitService } from '../services/gitService.js';
|
||||||
import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js';
|
|
||||||
|
|
||||||
import { ShellTool } from '../tools/shell.js';
|
import { ShellTool } from '../tools/shell.js';
|
||||||
import { ReadFileTool } from '../tools/read-file.js';
|
import { ReadFileTool } from '../tools/read-file.js';
|
||||||
import { GrepTool } from '../tools/grep.js';
|
import { GrepTool } from '../tools/grep.js';
|
||||||
@@ -180,10 +178,6 @@ describe('Server Config (config.ts)', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
// Reset mocks if necessary
|
// Reset mocks if necessary
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
vi.spyOn(
|
|
||||||
ClearcutLogger.prototype,
|
|
||||||
'logStartSessionEvent',
|
|
||||||
).mockImplementation(() => undefined);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('initialize', () => {
|
describe('initialize', () => {
|
||||||
@@ -432,18 +426,6 @@ describe('Server Config (config.ts)', () => {
|
|||||||
expect(config.getUsageStatisticsEnabled()).toBe(enabled);
|
expect(config.getUsageStatisticsEnabled()).toBe(enabled);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
it('logs the session start event', async () => {
|
|
||||||
const config = new Config({
|
|
||||||
...baseParams,
|
|
||||||
usageStatisticsEnabled: true,
|
|
||||||
});
|
|
||||||
await config.refreshAuth(AuthType.USE_GEMINI);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
ClearcutLogger.prototype.logStartSessionEvent,
|
|
||||||
).toHaveBeenCalledOnce();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Telemetry Settings', () => {
|
describe('Telemetry Settings', () => {
|
||||||
|
|||||||
@@ -42,7 +42,6 @@ import {
|
|||||||
uiTelemetryService,
|
uiTelemetryService,
|
||||||
} from '../telemetry/index.js';
|
} from '../telemetry/index.js';
|
||||||
import { tokenLimit } from '../core/tokenLimits.js';
|
import { tokenLimit } from '../core/tokenLimits.js';
|
||||||
import { StartSessionEvent } from '../telemetry/index.js';
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_GEMINI_EMBEDDING_MODEL,
|
DEFAULT_GEMINI_EMBEDDING_MODEL,
|
||||||
DEFAULT_GEMINI_FLASH_MODEL,
|
DEFAULT_GEMINI_FLASH_MODEL,
|
||||||
@@ -55,10 +54,7 @@ import { ideContextStore } from '../ide/ideContext.js';
|
|||||||
import { WriteTodosTool } from '../tools/write-todos.js';
|
import { WriteTodosTool } from '../tools/write-todos.js';
|
||||||
import type { FileSystemService } from '../services/fileSystemService.js';
|
import type { FileSystemService } from '../services/fileSystemService.js';
|
||||||
import { StandardFileSystemService } from '../services/fileSystemService.js';
|
import { StandardFileSystemService } from '../services/fileSystemService.js';
|
||||||
import {
|
import { logRipgrepFallback } from '../telemetry/loggers.js';
|
||||||
logCliConfiguration,
|
|
||||||
logRipgrepFallback,
|
|
||||||
} from '../telemetry/loggers.js';
|
|
||||||
import { RipgrepFallbackEvent } from '../telemetry/types.js';
|
import { RipgrepFallbackEvent } from '../telemetry/types.js';
|
||||||
import type { FallbackModelHandler } from '../fallback/types.js';
|
import type { FallbackModelHandler } from '../fallback/types.js';
|
||||||
import { ModelRouterService } from '../routing/modelRouterService.js';
|
import { ModelRouterService } from '../routing/modelRouterService.js';
|
||||||
@@ -576,9 +572,6 @@ export class Config {
|
|||||||
|
|
||||||
// Reset the session flag since we're explicitly changing auth and using default model
|
// Reset the session flag since we're explicitly changing auth and using default model
|
||||||
this.inFallbackMode = false;
|
this.inFallbackMode = false;
|
||||||
|
|
||||||
// Logging the cli configuration here as the auth related configuration params would have been loaded by this point
|
|
||||||
logCliConfiguration(this, new StartSessionEvent(this, this.toolRegistry));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getUserTier(): UserTierId | undefined {
|
getUserTier(): UserTierId | undefined {
|
||||||
|
|||||||
Reference in New Issue
Block a user