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
+21 -4
View File
@@ -27,12 +27,14 @@ import { convert } from 'html-to-text';
import {
logWebFetchFallbackAttempt,
WebFetchFallbackAttemptEvent,
logNetworkRetryAttempt,
NetworkRetryAttemptEvent,
} from '../telemetry/index.js';
import { LlmRole } from '../telemetry/llmRole.js';
import { WEB_FETCH_TOOL_NAME } from './tool-names.js';
import { debugLogger } from '../utils/debugLogger.js';
import { coreEvents } from '../utils/events.js';
import { retryWithBackoff } from '../utils/retry.js';
import { retryWithBackoff, getRetryErrorType } from '../utils/retry.js';
import { WEB_FETCH_DEFINITION } from './definitions/coreTools.js';
import { resolveToolDeclaration } from './definitions/resolver.js';
import { LRUCache } from 'mnemonist';
@@ -188,13 +190,28 @@ class WebFetchToolInvocation extends BaseToolInvocation<
}
private handleRetry(attempt: number, error: unknown, delayMs: number): void {
const maxAttempts = this.config.getMaxAttempts();
const modelName = 'Web Fetch';
const errorType = getRetryErrorType(error);
coreEvents.emitRetryAttempt({
attempt,
maxAttempts: this.config.getMaxAttempts(),
maxAttempts,
delayMs,
error: error instanceof Error ? error.message : String(error),
model: 'Web Fetch',
error: errorType,
model: modelName,
});
logNetworkRetryAttempt(
this.config,
new NetworkRetryAttemptEvent(
attempt,
maxAttempts,
errorType,
delayMs,
modelName,
),
);
}
private async executeFallback(signal: AbortSignal): Promise<ToolResult> {