feat: add role-specific statistics to telemetry and UI (cont. #15234) (#18824)

Co-authored-by: Yuna Seol <yunaseol@google.com>
This commit is contained in:
Yuna Seol
2026-02-17 12:32:30 -05:00
committed by GitHub
parent 14aabbbe8b
commit 8aca3068cf
51 changed files with 826 additions and 20 deletions
@@ -181,6 +181,7 @@ describe('UiTelemetryService', () => {
thoughts: 2,
tool: 3,
},
roles: {},
});
expect(service.getLastPromptTokenCount()).toBe(0);
});
@@ -236,6 +237,7 @@ describe('UiTelemetryService', () => {
thoughts: 6,
tool: 9,
},
roles: {},
});
expect(service.getLastPromptTokenCount()).toBe(0);
});
@@ -311,6 +313,7 @@ describe('UiTelemetryService', () => {
thoughts: 0,
tool: 0,
},
roles: {},
});
});
@@ -356,6 +359,35 @@ describe('UiTelemetryService', () => {
thoughts: 2,
tool: 3,
},
roles: {},
});
});
it('should update role metrics when processing an ApiErrorEvent with a role', () => {
const event = {
'event.name': EVENT_API_ERROR,
model: 'gemini-2.5-pro',
duration_ms: 300,
error: 'Something went wrong',
role: 'utility_tool',
} as unknown as ApiErrorEvent & { 'event.name': typeof EVENT_API_ERROR };
service.addEvent(event);
const metrics = service.getMetrics();
expect(metrics.models['gemini-2.5-pro'].roles['utility_tool']).toEqual({
totalRequests: 1,
totalErrors: 1,
totalLatencyMs: 300,
tokens: {
input: 0,
prompt: 0,
candidates: 0,
total: 0,
cached: 0,
thoughts: 0,
tool: 0,
},
});
});
});