fix(metrics) - Remove the error field from ApiResponseEvent (#8207)

Co-authored-by: Shi Shu <shii@google.com>
This commit is contained in:
shishu314
2025-09-11 13:35:17 -04:00
committed by GitHub
parent 6be054513b
commit 5504f933e1
6 changed files with 4 additions and 57 deletions

View File

@@ -557,10 +557,6 @@ export class ClearcutLogger {
gemini_cli_key: EventMetadataKey.GEMINI_CLI_API_RESPONSE_DURATION_MS,
value: JSON.stringify(event.duration_ms),
},
{
gemini_cli_key: EventMetadataKey.GEMINI_CLI_API_ERROR_MESSAGE,
value: JSON.stringify(event.error),
},
{
gemini_cli_key:
EventMetadataKey.GEMINI_CLI_API_RESPONSE_INPUT_TOKEN_COUNT,

View File

@@ -6,6 +6,8 @@
// Defines valid event metadata keys for Clearcut logging.
export enum EventMetadataKey {
// Deleted enums: 24
GEMINI_CLI_KEY_UNKNOWN = 0,
// ==========================================================================
@@ -100,9 +102,6 @@ export enum EventMetadataKey {
// Logs the duration of the API call in milliseconds.
GEMINI_CLI_API_RESPONSE_DURATION_MS = 23,
// Logs the error message of the API call, if any.
GEMINI_CLI_API_ERROR_MESSAGE = 24,
// Logs the input token count of the API call.
GEMINI_CLI_API_RESPONSE_INPUT_TOKEN_COUNT = 25,

View File

@@ -320,7 +320,6 @@ describe('loggers', () => {
response_text: 'test-response',
prompt_id: 'prompt-id-1',
auth_type: 'oauth-personal',
error: undefined,
},
});
@@ -329,7 +328,6 @@ describe('loggers', () => {
'test-model',
100,
200,
undefined,
);
expect(mockMetrics.recordTokenUsageMetrics).toHaveBeenCalledWith(
@@ -345,45 +343,6 @@ describe('loggers', () => {
'event.timestamp': '2025-01-01T00:00:00.000Z',
});
});
it('should log an API response with an error', () => {
const usageData: GenerateContentResponseUsageMetadata = {
promptTokenCount: 17,
candidatesTokenCount: 50,
cachedContentTokenCount: 10,
thoughtsTokenCount: 5,
toolUsePromptTokenCount: 2,
};
const event = new ApiResponseEvent(
'test-model',
100,
'prompt-id-1',
AuthType.USE_GEMINI,
usageData,
'test-response',
'test-error',
);
logApiResponse(mockConfig, event);
expect(mockLogger.emit).toHaveBeenCalledWith({
body: 'API response from test-model. Status: 200. Duration: 100ms.',
attributes: {
'session.id': 'test-session-id',
'user.email': 'test-user@example.com',
...event,
'event.name': EVENT_API_RESPONSE,
'event.timestamp': '2025-01-01T00:00:00.000Z',
'error.message': 'test-error',
},
});
expect(mockUiEvent.addEvent).toHaveBeenCalledWith({
...event,
'event.name': EVENT_API_RESPONSE,
'event.timestamp': '2025-01-01T00:00:00.000Z',
});
});
});
describe('logApiRequest', () => {

View File

@@ -376,9 +376,7 @@ export function logApiResponse(config: Config, event: ApiResponseEvent): void {
if (event.response_text) {
attributes['response_text'] = event.response_text;
}
if (event.error) {
attributes['error.message'] = event.error;
} else if (event.status_code) {
if (event.status_code) {
if (typeof event.status_code === 'number') {
attributes[SemanticAttributes.HTTP_STATUS_CODE] = event.status_code;
}
@@ -395,7 +393,6 @@ export function logApiResponse(config: Config, event: ApiResponseEvent): void {
event.model,
event.duration_ms,
event.status_code,
event.error,
);
recordTokenUsageMetrics(
config,

View File

@@ -174,7 +174,6 @@ export function recordApiResponseMetrics(
model: string,
durationMs: number,
statusCode?: number | string,
error?: string,
): void {
if (
!apiRequestCounter ||
@@ -185,7 +184,7 @@ export function recordApiResponseMetrics(
const metricAttributes: Attributes = {
...getCommonAttributes(config),
model,
status_code: statusCode ?? (error ? 'error' : 'ok'),
status_code: statusCode ?? 'ok',
};
apiRequestCounter.add(1, metricAttributes);
apiRequestLatencyHistogram.record(durationMs, {

View File

@@ -236,7 +236,6 @@ export class ApiResponseEvent implements BaseTelemetryEvent {
model: string;
status_code?: number | string;
duration_ms: number;
error?: string;
input_token_count: number;
output_token_count: number;
cached_content_token_count: number;
@@ -254,7 +253,6 @@ export class ApiResponseEvent implements BaseTelemetryEvent {
auth_type?: string,
usage_data?: GenerateContentResponseUsageMetadata,
response_text?: string,
error?: string,
) {
this['event.name'] = 'api_response';
this['event.timestamp'] = new Date().toISOString();
@@ -268,7 +266,6 @@ export class ApiResponseEvent implements BaseTelemetryEvent {
this.tool_token_count = usage_data?.toolUsePromptTokenCount ?? 0;
this.total_token_count = usage_data?.totalTokenCount ?? 0;
this.response_text = response_text;
this.error = error;
this.prompt_id = prompt_id;
this.auth_type = auth_type;
}