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), );