Add telemetry to rewind (#18122)

This commit is contained in:
Adib234
2026-02-03 16:17:29 -05:00
committed by GitHub
parent 69c0585ab2
commit 53027af94c
7 changed files with 76 additions and 0 deletions

View File

@@ -41,6 +41,8 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => {
...actual.coreEvents,
emitFeedback: vi.fn(),
},
logRewind: vi.fn(),
RewindEvent: class {},
};
});

View File

@@ -19,6 +19,8 @@ import {
checkExhaustive,
coreEvents,
debugLogger,
logRewind,
RewindEvent,
type ChatRecordingService,
type GeminiClient,
} from '@google/gemini-cli-core';
@@ -144,6 +146,9 @@ export const rewindCommand: SlashCommand = {
context.ui.removeComponent();
}}
onRewind={async (messageId, newText, outcome) => {
if (outcome !== RewindOutcome.Cancel) {
logRewind(config, new RewindEvent(outcome));
}
switch (outcome) {
case RewindOutcome.Cancel:
context.ui.removeComponent();

View File

@@ -18,6 +18,7 @@ import type {
LoopDetectedEvent,
NextSpeakerCheckEvent,
SlashCommandEvent,
RewindEvent,
MalformedJsonResponseEvent,
IdeConnectionEvent,
ConversationFinishedEvent,
@@ -78,6 +79,7 @@ export enum EventNames {
LOOP_DETECTION_DISABLED = 'loop_detection_disabled',
NEXT_SPEAKER_CHECK = 'next_speaker_check',
SLASH_COMMAND = 'slash_command',
REWIND = 'rewind',
MALFORMED_JSON_RESPONSE = 'malformed_json_response',
IDE_CONNECTION = 'ide_connection',
KITTY_SEQUENCE_OVERFLOW = 'kitty_sequence_overflow',
@@ -945,6 +947,18 @@ export class ClearcutLogger {
this.flushIfNeeded();
}
logRewindEvent(event: RewindEvent): void {
const data: EventValue[] = [
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_REWIND_OUTCOME,
value: event.outcome,
},
];
this.enqueueLogEvent(this.createLogEvent(EventNames.REWIND, data));
this.flushIfNeeded();
}
logMalformedJsonResponseEvent(event: MalformedJsonResponseEvent): void {
const data: EventValue[] = [
{

View File

@@ -544,6 +544,12 @@ export enum EventMetadataKey {
GEMINI_CLI_APPROVAL_MODE_DURATION_MS = 143,
// ==========================================================================
// Rewind Event Keys
// ==========================================================================
// Logs the outcome of a rewind operation.
GEMINI_CLI_REWIND_OUTCOME = 144,
// Model Routing Event Keys (Cont.)
// ==========================================================================

View File

@@ -46,6 +46,7 @@ export {
logExtensionUninstall,
logExtensionUpdateEvent,
logWebFetchFallbackAttempt,
logRewind,
} from './loggers.js';
export type { SlashCommandEvent, ChatCompressionEvent } from './types.js';
export {
@@ -62,6 +63,7 @@ export {
ToolOutputTruncatedEvent,
WebFetchFallbackAttemptEvent,
ToolCallDecision,
RewindEvent,
} from './types.js';
export { makeSlashCommandEvent, makeChatCompressionEvent } from './types.js';
export type { TelemetryEvent } from './types.js';

View File

@@ -12,6 +12,7 @@ import {
EVENT_API_ERROR,
EVENT_API_RESPONSE,
EVENT_TOOL_CALL,
EVENT_REWIND,
} from './types.js';
import type {
ApiErrorEvent,
@@ -27,6 +28,7 @@ import type {
LoopDetectedEvent,
LoopDetectionDisabledEvent,
SlashCommandEvent,
RewindEvent,
ConversationFinishedEvent,
ChatCompressionEvent,
MalformedJsonResponseEvent,
@@ -351,6 +353,24 @@ export function logSlashCommand(
});
}
export function logRewind(config: Config, event: RewindEvent): void {
const uiEvent = {
...event,
'event.name': EVENT_REWIND,
'event.timestamp': new Date().toISOString(),
} as UiEvent;
uiTelemetryService.addEvent(uiEvent);
ClearcutLogger.getInstance(config)?.logRewindEvent(event);
bufferTelemetryEvent(() => {
const logger = logs.getLogger(SERVICE_NAME);
const logRecord: LogRecord = {
body: event.toLogBody(),
attributes: event.toOpenTelemetryAttributes(config),
};
logger.emit(logRecord);
});
}
export function logIdeConnection(
config: Config,
event: IdeConnectionEvent,

View File

@@ -889,6 +889,32 @@ export enum SlashCommandStatus {
ERROR = 'error',
}
export const EVENT_REWIND = 'gemini_cli.rewind';
export class RewindEvent implements BaseTelemetryEvent {
'event.name': 'rewind';
'event.timestamp': string;
outcome: string;
constructor(outcome: string) {
this['event.name'] = 'rewind';
this['event.timestamp'] = new Date().toISOString();
this.outcome = outcome;
}
toOpenTelemetryAttributes(config: Config): LogAttributes {
return {
...getCommonAttributes(config),
'event.name': EVENT_REWIND,
'event.timestamp': this['event.timestamp'],
outcome: this.outcome,
};
}
toLogBody(): string {
return `Rewind performed. Outcome: ${this.outcome}.`;
}
}
export const EVENT_CHAT_COMPRESSION = 'gemini_cli.chat_compression';
export interface ChatCompressionEvent extends BaseTelemetryEvent {
'event.name': 'chat_compression';
@@ -1577,6 +1603,7 @@ export type TelemetryEvent =
| StartupStatsEvent
| WebFetchFallbackAttemptEvent
| EditStrategyEvent
| RewindEvent
| EditCorrectionEvent;
export const EVENT_EXTENSION_DISABLE = 'gemini_cli.extension_disable';