mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
feat(telemetry): implement retry attempt telemetry for network related retries (#22027)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
@@ -99,8 +99,46 @@ function getNetworkErrorCode(error: unknown): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const FETCH_FAILED_MESSAGE = 'fetch failed';
|
||||
const INCOMPLETE_JSON_MESSAGE = 'incomplete json segment';
|
||||
export const FETCH_FAILED_MESSAGE = 'fetch failed';
|
||||
export const INCOMPLETE_JSON_MESSAGE = 'incomplete json segment';
|
||||
|
||||
/**
|
||||
* Categorizes an error for retry telemetry purposes.
|
||||
* Returns a safe string without PII.
|
||||
*/
|
||||
export function getRetryErrorType(error: unknown): string {
|
||||
if (error === 'Invalid content') {
|
||||
return 'INVALID_CONTENT';
|
||||
}
|
||||
|
||||
const errorCode = getNetworkErrorCode(error);
|
||||
if (errorCode && RETRYABLE_NETWORK_CODES.includes(errorCode)) {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
const lowerMessage = error.message.toLowerCase();
|
||||
if (lowerMessage.includes(FETCH_FAILED_MESSAGE)) {
|
||||
return 'FETCH_FAILED';
|
||||
}
|
||||
if (lowerMessage.includes(INCOMPLETE_JSON_MESSAGE)) {
|
||||
return 'INCOMPLETE_JSON';
|
||||
}
|
||||
}
|
||||
|
||||
const status = getErrorStatus(error);
|
||||
if (status !== undefined) {
|
||||
if (status === 429) return 'QUOTA_EXCEEDED';
|
||||
if (status >= 500 && status < 600) return 'SERVER_ERROR';
|
||||
return `HTTP_${status}`;
|
||||
}
|
||||
|
||||
if (error instanceof Error) {
|
||||
return error.name;
|
||||
}
|
||||
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
|
||||
/**
|
||||
* Default predicate function to determine if a retry should be attempted.
|
||||
|
||||
Reference in New Issue
Block a user