feat(telemetry): implement Clearcut logging for startup statistics (#21172)

Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
Yuna Seol
2026-03-05 13:21:55 -05:00
committed by GitHub
parent 93d9adc03c
commit 31d65f40bd
3 changed files with 44 additions and 1 deletions

View File

@@ -49,6 +49,7 @@ import type {
ToolOutputMaskingEvent,
KeychainAvailabilityEvent,
TokenStorageInitializationEvent,
StartupStatsEvent,
} from '../types.js';
import { EventMetadataKey } from './event-metadata-key.js';
import type { Config } from '../../config/config.js';
@@ -117,6 +118,7 @@ export enum EventNames {
TOKEN_STORAGE_INITIALIZATION = 'token_storage_initialization',
CONSECA_POLICY_GENERATION = 'conseca_policy_generation',
CONSECA_VERDICT = 'conseca_verdict',
STARTUP_STATS = 'startup_stats',
}
export interface LogResponse {
@@ -1691,6 +1693,30 @@ export class ClearcutLogger {
this.flushIfNeeded();
}
logStartupStatsEvent(event: StartupStatsEvent): void {
const data: EventValue[] = [
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_STARTUP_PHASES,
value: JSON.stringify(event.phases),
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_STARTUP_OS_PLATFORM,
value: event.os_platform,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_STARTUP_OS_RELEASE,
value: event.os_release,
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_STARTUP_IS_DOCKER,
value: JSON.stringify(event.is_docker),
},
];
this.enqueueLogEvent(this.createLogEvent(EventNames.STARTUP_STATS, data));
this.flushIfNeeded();
}
/**
* Adds default fields to data, and returns a new data array. This fields
* should exist on all log events.

View File

@@ -7,7 +7,7 @@
// Defines valid event metadata keys for Clearcut logging.
export enum EventMetadataKey {
// Deleted enums: 24
// Next ID: 172
// Next ID: 176
GEMINI_CLI_KEY_UNKNOWN = 0,
@@ -54,6 +54,22 @@ export enum EventMetadataKey {
// Logs the output format of the session.
GEMINI_CLI_START_SESSION_OUTPUT_FORMAT = 94,
// ==========================================================================
// Startup Stats Event Keys
// ==========================================================================
// Logs the array of startup phases.
GEMINI_CLI_STARTUP_PHASES = 172,
// Logs the OS platform for startup stats.
GEMINI_CLI_STARTUP_OS_PLATFORM = 173,
// Logs the OS release for startup stats.
GEMINI_CLI_STARTUP_OS_RELEASE = 174,
// Logs whether the CLI is running in docker for startup stats.
GEMINI_CLI_STARTUP_IS_DOCKER = 175,
// ==========================================================================
// User Prompt Event Keys
// ===========================================================================

View File

@@ -791,6 +791,7 @@ export function logStartupStats(
config: Config,
event: StartupStatsEvent,
): void {
ClearcutLogger.getInstance(config)?.logStartupStatsEvent(event);
bufferTelemetryEvent(() => {
// Wait for experiments to load before emitting so we capture experimentIds
void config