diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts index 700e67591e..10705cd24f 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.test.ts @@ -413,7 +413,7 @@ describe('ClearcutLogger', () => { vi.stubEnv('CURSOR_TRACE_ID', ''); } const event = logger?.createLogEvent(EventNames.API_ERROR, []); - expect(event?.event_metadata[0][3]).toEqual({ + expect(event?.event_metadata[0]).toContainEqual({ gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE, value: expectedValue, }); diff --git a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts index 2ab3cf2441..93eec836ef 100644 --- a/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts +++ b/packages/core/src/telemetry/clearcut-logger/clearcut-logger.ts @@ -250,6 +250,39 @@ export class ClearcutLogger { } } + createBasicLogEvent( + eventName: EventNames, + data: EventValue[] = [], + ): LogEvent { + const surface = determineSurface(); + return { + console_type: 'GEMINI_CLI', + application: 102, // GEMINI_CLI + event_name: eventName as string, + event_metadata: [ + [ + ...data, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE, + value: surface, + }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_VERSION, + value: CLI_VERSION, + }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_GIT_COMMIT_HASH, + value: GIT_COMMIT_INFO, + }, + { + gemini_cli_key: EventMetadataKey.GEMINI_CLI_OS, + value: process.platform, + }, + ], + ], + }; + } + createLogEvent(eventName: EventNames, data: EventValue[] = []): LogEvent { const email = this.userAccountManager.getCachedGoogleAccount(); @@ -260,12 +293,7 @@ export class ClearcutLogger { data = this.addDefaultFields(data, totalAccounts); - const logEvent: LogEvent = { - console_type: 'GEMINI_CLI', - application: 102, // GEMINI_CLI - event_name: eventName as string, - event_metadata: [data], - }; + const logEvent = this.createBasicLogEvent(eventName, data); // Should log either email or install ID, not both. See go/cloudmill-1p-oss-instrumentation#define-sessionable-id if (email) { @@ -921,7 +949,7 @@ export class ClearcutLogger { ]; this.enqueueLogEvent( - this.createLogEvent(EventNames.EXTENSION_INSTALL, data), + this.createBasicLogEvent(EventNames.EXTENSION_INSTALL, data), ); this.flushToClearcut().catch((error) => { debugLogger.debug('Error flushing to Clearcut:', error); @@ -945,7 +973,7 @@ export class ClearcutLogger { ]; this.enqueueLogEvent( - this.createLogEvent(EventNames.EXTENSION_UNINSTALL, data), + this.createBasicLogEvent(EventNames.EXTENSION_UNINSTALL, data), ); this.flushToClearcut().catch((error) => { debugLogger.debug('Error flushing to Clearcut:', error); @@ -981,7 +1009,7 @@ export class ClearcutLogger { ]; this.enqueueLogEvent( - this.createLogEvent(EventNames.EXTENSION_UPDATE, data), + this.createBasicLogEvent(EventNames.EXTENSION_UPDATE, data), ); this.flushToClearcut().catch((error) => { debugLogger.debug('Error flushing to Clearcut:', error); @@ -1070,7 +1098,7 @@ export class ClearcutLogger { ]; this.enqueueLogEvent( - this.createLogEvent(EventNames.EXTENSION_ENABLE, data), + this.createBasicLogEvent(EventNames.EXTENSION_ENABLE, data), ); this.flushToClearcut().catch((error) => { debugLogger.debug('Error flushing to Clearcut:', error); @@ -1109,7 +1137,7 @@ export class ClearcutLogger { ]; this.enqueueLogEvent( - this.createLogEvent(EventNames.EXTENSION_DISABLE, data), + this.createBasicLogEvent(EventNames.EXTENSION_DISABLE, data), ); this.flushToClearcut().catch((error) => { debugLogger.debug('Error flushing to Clearcut:', error); @@ -1207,8 +1235,6 @@ export class ClearcutLogger { * should exist on all log events. */ addDefaultFields(data: EventValue[], totalAccounts: number): EventValue[] { - const surface = determineSurface(); - const defaultLogMetadata: EventValue[] = [ { gemini_cli_key: EventMetadataKey.GEMINI_CLI_SESSION_ID, @@ -1224,26 +1250,10 @@ export class ClearcutLogger { gemini_cli_key: EventMetadataKey.GEMINI_CLI_GOOGLE_ACCOUNTS_COUNT, value: `${totalAccounts}`, }, - { - gemini_cli_key: EventMetadataKey.GEMINI_CLI_SURFACE, - value: surface, - }, - { - gemini_cli_key: EventMetadataKey.GEMINI_CLI_VERSION, - value: CLI_VERSION, - }, - { - gemini_cli_key: EventMetadataKey.GEMINI_CLI_GIT_COMMIT_HASH, - value: GIT_COMMIT_INFO, - }, { gemini_cli_key: EventMetadataKey.GEMINI_CLI_PROMPT_ID, value: this.promptId, }, - { - gemini_cli_key: EventMetadataKey.GEMINI_CLI_OS, - value: process.platform, - }, { gemini_cli_key: EventMetadataKey.GEMINI_CLI_NODE_VERSION, value: process.versions.node,