feat: Add OTEL log event gemini_cli.startup_stats for startup stats. (#14734)

This commit is contained in:
Kevin Ramdass
2025-12-08 12:29:50 -08:00
committed by GitHub
parent f8c4ff635c
commit 159be887df
4 changed files with 130 additions and 0 deletions
@@ -13,6 +13,11 @@ vi.mock('./metrics.js', () => ({
recordStartupPerformance: vi.fn(),
}));
// Mock loggers module
vi.mock('./loggers.js', () => ({
logStartupStats: vi.fn(),
}));
// Mock os module
vi.mock('node:os', () => ({
platform: vi.fn(() => 'darwin'),
@@ -33,6 +38,7 @@ describe('StartupProfiler', () => {
let profiler: StartupProfiler;
let mockConfig: Config;
let recordStartupPerformance: ReturnType<typeof vi.fn>;
let logStartupStats: ReturnType<typeof vi.fn>;
beforeEach(async () => {
vi.resetAllMocks();
@@ -42,6 +48,9 @@ describe('StartupProfiler', () => {
recordStartupPerformance =
metricsModule.recordStartupPerformance as ReturnType<typeof vi.fn>;
const loggersModule = await import('./loggers.js');
logStartupStats = loggersModule.logStartupStats as ReturnType<typeof vi.fn>;
// Create a fresh profiler instance
profiler = StartupProfiler.getInstance();
@@ -343,5 +352,28 @@ describe('StartupProfiler', () => {
expect.objectContaining({ phase: 'complete_phase' }),
);
});
it('should log startup stats event', () => {
const handle = profiler.start('test_phase');
handle?.end();
profiler.flush(mockConfig);
expect(logStartupStats).toHaveBeenCalledWith(
mockConfig,
expect.objectContaining({
phases: expect.arrayContaining([
expect.objectContaining({
name: 'test_phase',
duration_ms: expect.any(Number),
start_time_usec: expect.any(Number),
end_time_usec: expect.any(Number),
}),
]),
os_platform: 'darwin',
os_release: '22.6.0',
is_docker: false,
}),
);
});
});
});