From 4b2c990368d5ed35592f31775caae86cb9ab3e72 Mon Sep 17 00:00:00 2001 From: Sandy Tao Date: Wed, 3 Sep 2025 13:09:38 -0700 Subject: [PATCH] fix(core): Fix more logging issues (#7674) --- .../core/src/core/loggingContentGenerator.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/src/core/loggingContentGenerator.ts b/packages/core/src/core/loggingContentGenerator.ts index 82e6dd1104..916750b3cf 100644 --- a/packages/core/src/core/loggingContentGenerator.ts +++ b/packages/core/src/core/loggingContentGenerator.ts @@ -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), );