Skip to content

Commit 6db64aa

Browse files
authored
fix(telemetry): Prevent duplicate StartSessionEvent logging (#12090)
1 parent abd22a7 commit 6db64aa

4 files changed

Lines changed: 32 additions & 26 deletions

File tree

packages/cli/src/core/initializer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {
1010
IdeConnectionType,
1111
logIdeConnection,
1212
type Config,
13+
StartSessionEvent,
14+
logCliConfiguration,
1315
} from '@google/gemini-cli-core';
1416
import { type LoadedSettings } from '../config/settings.js';
1517
import { performInitialAuth } from './auth.js';
@@ -42,6 +44,11 @@ export async function initializeApp(
4244
const shouldOpenAuthDialog =
4345
settings.merged.security?.auth?.selectedType === undefined || !!authError;
4446

47+
logCliConfiguration(
48+
config,
49+
new StartSessionEvent(config, config.getToolRegistry()),
50+
);
51+
4552
if (config.getIdeMode()) {
4653
const ideClient = await IdeClient.getInstance();
4754
await ideClient.connect();

packages/cli/src/gemini.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ describe('gemini.tsx main function', () => {
174174
getMessageBus: () => ({
175175
subscribe: vi.fn(),
176176
}),
177+
getToolRegistry: vi.fn(),
178+
getContentGeneratorConfig: vi.fn(),
179+
getModel: () => 'gemini-pro',
180+
getEmbeddingModel: () => 'embedding-001',
181+
getApprovalMode: () => 'default',
182+
getCoreTools: () => [],
183+
getTelemetryEnabled: () => false,
184+
getTelemetryLogPromptsEnabled: () => false,
185+
getFileFilteringRespectGitIgnore: () => true,
186+
getOutputFormat: () => 'text',
187+
getExtensions: () => [],
188+
getUsageStatisticsEnabled: () => false,
177189
} as unknown as Config;
178190
});
179191
vi.mocked(loadSettings).mockReturnValue({
@@ -309,6 +321,18 @@ describe('gemini.tsx main function kitty protocol', () => {
309321
getMessageBus: () => ({
310322
subscribe: vi.fn(),
311323
}),
324+
getToolRegistry: vi.fn(),
325+
getContentGeneratorConfig: vi.fn(),
326+
getModel: () => 'gemini-pro',
327+
getEmbeddingModel: () => 'embedding-001',
328+
getApprovalMode: () => 'default',
329+
getCoreTools: () => [],
330+
getTelemetryEnabled: () => false,
331+
getTelemetryLogPromptsEnabled: () => false,
332+
getFileFilteringRespectGitIgnore: () => true,
333+
getOutputFormat: () => 'text',
334+
getExtensions: () => [],
335+
getUsageStatisticsEnabled: () => false,
312336
} as unknown as Config);
313337
vi.mocked(loadSettings).mockReturnValue({
314338
errors: [],

packages/core/src/config/config.test.ts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import {
2525
} from '../core/contentGenerator.js';
2626
import { GeminiClient } from '../core/client.js';
2727
import { GitService } from '../services/gitService.js';
28-
import { ClearcutLogger } from '../telemetry/clearcut-logger/clearcut-logger.js';
29-
3028
import { ShellTool } from '../tools/shell.js';
3129
import { ReadFileTool } from '../tools/read-file.js';
3230
import { GrepTool } from '../tools/grep.js';
@@ -180,10 +178,6 @@ describe('Server Config (config.ts)', () => {
180178
beforeEach(() => {
181179
// Reset mocks if necessary
182180
vi.clearAllMocks();
183-
vi.spyOn(
184-
ClearcutLogger.prototype,
185-
'logStartSessionEvent',
186-
).mockImplementation(() => undefined);
187181
});
188182

189183
describe('initialize', () => {
@@ -432,18 +426,6 @@ describe('Server Config (config.ts)', () => {
432426
expect(config.getUsageStatisticsEnabled()).toBe(enabled);
433427
},
434428
);
435-
436-
it('logs the session start event', async () => {
437-
const config = new Config({
438-
...baseParams,
439-
usageStatisticsEnabled: true,
440-
});
441-
await config.refreshAuth(AuthType.USE_GEMINI);
442-
443-
expect(
444-
ClearcutLogger.prototype.logStartSessionEvent,
445-
).toHaveBeenCalledOnce();
446-
});
447429
});
448430

449431
describe('Telemetry Settings', () => {

packages/core/src/config/config.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import {
4242
uiTelemetryService,
4343
} from '../telemetry/index.js';
4444
import { tokenLimit } from '../core/tokenLimits.js';
45-
import { StartSessionEvent } from '../telemetry/index.js';
4645
import {
4746
DEFAULT_GEMINI_EMBEDDING_MODEL,
4847
DEFAULT_GEMINI_FLASH_MODEL,
@@ -55,10 +54,7 @@ import { ideContextStore } from '../ide/ideContext.js';
5554
import { WriteTodosTool } from '../tools/write-todos.js';
5655
import type { FileSystemService } from '../services/fileSystemService.js';
5756
import { StandardFileSystemService } from '../services/fileSystemService.js';
58-
import {
59-
logCliConfiguration,
60-
logRipgrepFallback,
61-
} from '../telemetry/loggers.js';
57+
import { logRipgrepFallback } from '../telemetry/loggers.js';
6258
import { RipgrepFallbackEvent } from '../telemetry/types.js';
6359
import type { FallbackModelHandler } from '../fallback/types.js';
6460
import { ModelRouterService } from '../routing/modelRouterService.js';
@@ -576,9 +572,6 @@ export class Config {
576572

577573
// Reset the session flag since we're explicitly changing auth and using default model
578574
this.inFallbackMode = false;
579-
580-
// Logging the cli configuration here as the auth related configuration params would have been loaded by this point
581-
logCliConfiguration(this, new StartSessionEvent(this, this.toolRegistry));
582575
}
583576

584577
getUserTier(): UserTierId | undefined {

0 commit comments

Comments
 (0)