feat(core): add telemetry for subagent execution (#10456)

This commit is contained in:
Abhi
2025-10-08 15:42:33 -04:00
committed by GitHub
parent b45bd5ff7b
commit c0552ceb22
11 changed files with 608 additions and 20 deletions
+43
View File
@@ -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);
}