Add support for logging the entire request and response object (#4725)

This commit is contained in:
anj-s 2025-07-24 11:45:53 -07:00 committed by GitHub
parent e05173d9cc
commit f9930c2d36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 12 deletions

View File

@ -26,10 +26,6 @@ import {
logApiResponse, logApiResponse,
logApiError, logApiError,
} from '../telemetry/loggers.js'; } from '../telemetry/loggers.js';
import {
getStructuredResponse,
getStructuredResponseFromParts,
} from '../utils/generateContentResponseUtilities.js';
import { import {
ApiErrorEvent, ApiErrorEvent,
ApiRequestEvent, ApiRequestEvent,
@ -142,11 +138,7 @@ export class GeminiChat {
} }
private _getRequestTextFromContents(contents: Content[]): string { private _getRequestTextFromContents(contents: Content[]): string {
return contents return JSON.stringify(contents);
.flatMap((content) => content.parts ?? [])
.map((part) => part.text)
.filter(Boolean)
.join('');
} }
private async _logApiRequest( private async _logApiRequest(
@ -318,7 +310,7 @@ export class GeminiChat {
durationMs, durationMs,
prompt_id, prompt_id,
response.usageMetadata, response.usageMetadata,
getStructuredResponse(response), JSON.stringify(response),
); );
this.sendPromise = (async () => { this.sendPromise = (async () => {
@ -554,12 +546,11 @@ export class GeminiChat {
allParts.push(...content.parts); allParts.push(...content.parts);
} }
} }
const fullText = getStructuredResponseFromParts(allParts);
await this._logApiResponse( await this._logApiResponse(
durationMs, durationMs,
prompt_id, prompt_id,
this.getFinalUsageMetadata(chunks), this.getFinalUsageMetadata(chunks),
fullText, JSON.stringify(chunks),
); );
} }
this.recordHistory(inputContent, outputContent); this.recordHistory(inputContent, outputContent);