mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-11 06:31:01 -07:00
fix(core): add telemetry support for smart edit correction events (#10378)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import type {
|
||||
ModelSlashCommandEvent,
|
||||
ExtensionDisableEvent,
|
||||
SmartEditStrategyEvent,
|
||||
SmartEditCorrectionEvent,
|
||||
} from '../types.js';
|
||||
import { EventMetadataKey } from './event-metadata-key.js';
|
||||
import type { Config } from '../../config/config.js';
|
||||
@@ -77,6 +78,7 @@ export enum EventNames {
|
||||
MODEL_ROUTING = 'model_routing',
|
||||
MODEL_SLASH_COMMAND = 'model_slash_command',
|
||||
SMART_EDIT_STRATEGY = 'smart_edit_strategy',
|
||||
SMART_EDIT_CORRECTION = 'smart_edit_correction',
|
||||
}
|
||||
|
||||
export interface LogResponse {
|
||||
@@ -1055,6 +1057,20 @@ export class ClearcutLogger {
|
||||
this.flushIfNeeded();
|
||||
}
|
||||
|
||||
logSmartEditCorrectionEvent(event: SmartEditCorrectionEvent): void {
|
||||
const data: EventValue[] = [
|
||||
{
|
||||
gemini_cli_key: EventMetadataKey.GEMINI_CLI_SMART_EDIT_CORRECTION,
|
||||
value: event.correction,
|
||||
},
|
||||
];
|
||||
|
||||
this.enqueueLogEvent(
|
||||
this.createLogEvent(EventNames.SMART_EDIT_CORRECTION, data),
|
||||
);
|
||||
this.flushIfNeeded();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds default fields to data, and returns a new data array. This fields
|
||||
* should exist on all log events.
|
||||
|
||||
@@ -88,6 +88,16 @@ export enum EventMetadataKey {
|
||||
// Logs the length of tool output
|
||||
GEMINI_CLI_TOOL_CALL_CONTENT_LENGTH = 93,
|
||||
|
||||
// ==========================================================================
|
||||
// Replace Tool Call Event Keys
|
||||
// ===========================================================================
|
||||
|
||||
// Logs a smart edit tool strategy choice.
|
||||
GEMINI_CLI_SMART_EDIT_STRATEGY = 109,
|
||||
|
||||
// Logs a smart edit correction event.
|
||||
GEMINI_CLI_SMART_EDIT_CORRECTION = 110,
|
||||
|
||||
// ==========================================================================
|
||||
// GenAI API Request Event Keys
|
||||
// ===========================================================================
|
||||
@@ -416,7 +426,4 @@ export enum EventMetadataKey {
|
||||
|
||||
// Logs an event when the user uses the /model command.
|
||||
GEMINI_CLI_MODEL_SLASH_COMMAND = 108,
|
||||
|
||||
// Logs a smart edit tool strategy choice.
|
||||
GEMINI_CLI_SMART_EDIT_STRATEGY = 109,
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export const EVENT_FILE_OPERATION = 'gemini_cli.file_operation';
|
||||
export const EVENT_MODEL_SLASH_COMMAND = 'gemini_cli.slash_command.model';
|
||||
export const EVENT_SMART_EDIT_STRATEGY = 'gemini_cli.smart_edit.strategy';
|
||||
export const EVENT_MODEL_ROUTING = 'gemini_cli.model_routing';
|
||||
export const EVENT_SMART_EDIT_CORRECTION = 'gemini_cli.smart_edit.correction';
|
||||
|
||||
// Performance Events
|
||||
export const EVENT_STARTUP_PERFORMANCE = 'gemini_cli.startup.performance';
|
||||
|
||||
@@ -35,6 +35,7 @@ import {
|
||||
EVENT_MODEL_SLASH_COMMAND,
|
||||
EVENT_EXTENSION_DISABLE,
|
||||
EVENT_SMART_EDIT_STRATEGY,
|
||||
EVENT_SMART_EDIT_CORRECTION,
|
||||
} from './constants.js';
|
||||
import type {
|
||||
ApiErrorEvent,
|
||||
@@ -66,6 +67,7 @@ import type {
|
||||
ExtensionInstallEvent,
|
||||
ModelSlashCommandEvent,
|
||||
SmartEditStrategyEvent,
|
||||
SmartEditCorrectionEvent,
|
||||
} from './types.js';
|
||||
import {
|
||||
recordApiErrorMetrics,
|
||||
@@ -839,3 +841,24 @@ export function logSmartEditStrategy(
|
||||
};
|
||||
logger.emit(logRecord);
|
||||
}
|
||||
|
||||
export function logSmartEditCorrectionEvent(
|
||||
config: Config,
|
||||
event: SmartEditCorrectionEvent,
|
||||
): void {
|
||||
ClearcutLogger.getInstance(config)?.logSmartEditCorrectionEvent(event);
|
||||
if (!isTelemetrySdkInitialized()) return;
|
||||
|
||||
const attributes: LogAttributes = {
|
||||
...getCommonAttributes(config),
|
||||
...event,
|
||||
'event.name': EVENT_SMART_EDIT_CORRECTION,
|
||||
};
|
||||
|
||||
const logger = logs.getLogger(SERVICE_NAME);
|
||||
const logRecord: LogRecord = {
|
||||
body: `Smart Edit Tool Correction: ${event.correction}`,
|
||||
attributes,
|
||||
};
|
||||
logger.emit(logRecord);
|
||||
}
|
||||
|
||||
@@ -714,3 +714,15 @@ export class SmartEditStrategyEvent implements BaseTelemetryEvent {
|
||||
this.strategy = strategy;
|
||||
}
|
||||
}
|
||||
|
||||
export class SmartEditCorrectionEvent implements BaseTelemetryEvent {
|
||||
'event.name': 'smart_edit_correction';
|
||||
'event.timestamp': string;
|
||||
correction: 'success' | 'failure';
|
||||
|
||||
constructor(correction: 'success' | 'failure') {
|
||||
this['event.name'] = 'smart_edit_correction';
|
||||
this['event.timestamp'] = new Date().toISOString();
|
||||
this.correction = correction;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import { applyReplacement } from './edit.js';
|
||||
import { safeLiteralReplace } from '../utils/textUtils.js';
|
||||
import { SmartEditStrategyEvent } from '../telemetry/types.js';
|
||||
import { logSmartEditStrategy } from '../telemetry/loggers.js';
|
||||
import { SmartEditCorrectionEvent } from '../telemetry/types.js';
|
||||
import { logSmartEditCorrectionEvent } from '../telemetry/loggers.js';
|
||||
|
||||
interface ReplacementContext {
|
||||
params: EditToolParams;
|
||||
@@ -416,7 +418,10 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
);
|
||||
|
||||
if (secondError) {
|
||||
// The fix failed, return the original error
|
||||
// The fix failed, log failure and return the original error
|
||||
const event = new SmartEditCorrectionEvent('failure');
|
||||
logSmartEditCorrectionEvent(this.config, event);
|
||||
|
||||
return {
|
||||
currentContent,
|
||||
newContent: currentContent,
|
||||
@@ -427,6 +432,9 @@ class EditToolInvocation implements ToolInvocation<EditToolParams, ToolResult> {
|
||||
};
|
||||
}
|
||||
|
||||
const event = new SmartEditCorrectionEvent('success');
|
||||
logSmartEditCorrectionEvent(this.config, event);
|
||||
|
||||
return {
|
||||
currentContent,
|
||||
newContent: secondAttemptResult.newContent,
|
||||
|
||||
Reference in New Issue
Block a user