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:
Aishanee Shah
2026-03-11 14:55:48 -04:00
committed by GitHub
parent 36ce2ba96e
commit 067e09a40b
13 changed files with 326 additions and 27 deletions
+40 -2
View File
@@ -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.