mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-13 21:32:56 -07:00
feat(core): add telemetry for subagent execution (#10456)
This commit is contained in:
@@ -37,6 +37,8 @@ import {
|
||||
EVENT_EXTENSION_DISABLE,
|
||||
EVENT_SMART_EDIT_STRATEGY,
|
||||
EVENT_SMART_EDIT_CORRECTION,
|
||||
EVENT_AGENT_START,
|
||||
EVENT_AGENT_FINISH,
|
||||
} from './constants.js';
|
||||
import type {
|
||||
ApiErrorEvent,
|
||||
@@ -69,6 +71,8 @@ import type {
|
||||
ModelSlashCommandEvent,
|
||||
SmartEditStrategyEvent,
|
||||
SmartEditCorrectionEvent,
|
||||
AgentStartEvent,
|
||||
AgentFinishEvent,
|
||||
} from './types.js';
|
||||
import {
|
||||
recordApiErrorMetrics,
|
||||
@@ -83,6 +87,7 @@ import {
|
||||
getConventionAttributes,
|
||||
recordTokenUsageMetrics,
|
||||
recordApiResponseMetrics,
|
||||
recordAgentRunMetrics,
|
||||
} from './metrics.js';
|
||||
import { isTelemetrySdkInitialized } from './sdk.js';
|
||||
import type { UiEvent } from './uiTelemetry.js';
|
||||
@@ -863,3 +868,41 @@ export function logSmartEditCorrectionEvent(
|
||||
};
|
||||
logger.emit(logRecord);
|
||||
}
|
||||
|
||||
export function logAgentStart(config: Config, event: AgentStartEvent): void {
|
||||
ClearcutLogger.getInstance(config)?.logAgentStartEvent(event);
|
||||
if (!isTelemetrySdkInitialized()) return;
|
||||
|
||||
const attributes: LogAttributes = {
|
||||
...getCommonAttributes(config),
|
||||
...event,
|
||||
'event.name': EVENT_AGENT_START,
|
||||
};
|
||||
|
||||
const logger = logs.getLogger(SERVICE_NAME);
|
||||
const logRecord: LogRecord = {
|
||||
body: `Agent ${event.agent_name} started. ID: ${event.agent_id}`,
|
||||
attributes,
|
||||
};
|
||||
logger.emit(logRecord);
|
||||
}
|
||||
|
||||
export function logAgentFinish(config: Config, event: AgentFinishEvent): void {
|
||||
ClearcutLogger.getInstance(config)?.logAgentFinishEvent(event);
|
||||
if (!isTelemetrySdkInitialized()) return;
|
||||
|
||||
const attributes: LogAttributes = {
|
||||
...getCommonAttributes(config),
|
||||
...event,
|
||||
'event.name': EVENT_AGENT_FINISH,
|
||||
};
|
||||
|
||||
const logger = logs.getLogger(SERVICE_NAME);
|
||||
const logRecord: LogRecord = {
|
||||
body: `Agent ${event.agent_name} finished. Reason: ${event.terminate_reason}. Duration: ${event.duration_ms}ms. Turns: ${event.turn_count}.`,
|
||||
attributes,
|
||||
};
|
||||
logger.emit(logRecord);
|
||||
|
||||
recordAgentRunMetrics(config, event);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user