feat(plan): create a metric for execution of plans generated in plan mode (#18236)

This commit is contained in:
Adib234
2026-02-05 18:46:34 -05:00
committed by GitHub
parent dd908a8d04
commit 3014614ffa
8 changed files with 173 additions and 2 deletions
@@ -96,6 +96,7 @@ describe('Telemetry Metrics', () => {
let recordAgentRunMetricsModule: typeof import('./metrics.js').recordAgentRunMetrics;
let recordLinesChangedModule: typeof import('./metrics.js').recordLinesChanged;
let recordSlowRenderModule: typeof import('./metrics.js').recordSlowRender;
let recordPlanExecutionModule: typeof import('./metrics.js').recordPlanExecution;
beforeEach(async () => {
vi.resetModules();
@@ -140,6 +141,7 @@ describe('Telemetry Metrics', () => {
recordAgentRunMetricsModule = metricsJsModule.recordAgentRunMetrics;
recordLinesChangedModule = metricsJsModule.recordLinesChanged;
recordSlowRenderModule = metricsJsModule.recordSlowRender;
recordPlanExecutionModule = metricsJsModule.recordPlanExecution;
const otelApiModule = await import('@opentelemetry/api');
@@ -218,6 +220,29 @@ describe('Telemetry Metrics', () => {
});
});
describe('recordPlanExecution', () => {
it('does not record metrics if not initialized', () => {
const config = makeFakeConfig({});
recordPlanExecutionModule(config, { approval_mode: 'default' });
expect(mockCounterAddFn).not.toHaveBeenCalled();
});
it('records a plan execution event when initialized', () => {
const config = makeFakeConfig({});
initializeMetricsModule(config);
recordPlanExecutionModule(config, { approval_mode: 'autoEdit' });
// Called for session, then for plan execution
expect(mockCounterAddFn).toHaveBeenCalledTimes(2);
expect(mockCounterAddFn).toHaveBeenNthCalledWith(2, 1, {
'session.id': 'test-session-id',
'installation.id': 'test-installation-id',
'user.email': 'test@example.com',
approval_mode: 'autoEdit',
});
});
});
describe('initializeMetrics', () => {
const mockConfig = {
getSessionId: () => 'test-session-id',