fix(core): Fix more logging issues (#7674)

This commit is contained in:
Sandy Tao
2025-09-03 13:09:38 -07:00
committed by GitHub
parent 3f26f9615c
commit 4b2c990368

View File

@@ -81,6 +81,7 @@ export class LoggingContentGenerator implements ContentGenerator {
private _logApiError(
durationMs: number,
error: unknown,
model: string,
prompt_id: string,
): void {
const errorMessage = error instanceof Error ? error.message : String(error);
@@ -89,7 +90,7 @@ export class LoggingContentGenerator implements ContentGenerator {
logApiError(
this.config,
new ApiErrorEvent(
this.config.getModel(),
model,
errorMessage,
durationMs,
prompt_id,
@@ -121,7 +122,7 @@ export class LoggingContentGenerator implements ContentGenerator {
return response;
} catch (error) {
const durationMs = Date.now() - startTime;
this._logApiError(durationMs, error, userPromptId);
this._logApiError(durationMs, error, req.model, userPromptId);
throw error;
}
}
@@ -138,7 +139,7 @@ export class LoggingContentGenerator implements ContentGenerator {
stream = await this.wrapped.generateContentStream(req, userPromptId);
} catch (error) {
const durationMs = Date.now() - startTime;
this._logApiError(durationMs, error, userPromptId);
this._logApiError(durationMs, error, req.model, userPromptId);
throw error;
}
@@ -165,15 +166,20 @@ export class LoggingContentGenerator implements ContentGenerator {
}
} catch (error) {
const durationMs = Date.now() - startTime;
this._logApiError(durationMs, error, userPromptId);
this._logApiError(
durationMs,
error,
responses[0]?.modelVersion || '',
userPromptId,
);
throw error;
}
const durationMs = Date.now() - startTime;
if (lastResponse) {
this._logApiResponse(
durationMs,
userPromptId,
responses[0]?.modelVersion || '',
userPromptId,
lastUsageMetadata,
JSON.stringify(responses),
);