From cd3c8abc8a07e201993e4194a1346dd0c5ff6046 Mon Sep 17 00:00:00 2001 From: Max Lord Date: Fri, 1 Nov 2024 16:18:56 -0400 Subject: [PATCH] Re-initializing GCP logger after it experiences a failure. --- js/plugins/google-cloud/src/gcpLogger.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/plugins/google-cloud/src/gcpLogger.ts b/js/plugins/google-cloud/src/gcpLogger.ts index 4a2bd7e178..861966d2d0 100644 --- a/js/plugins/google-cloud/src/gcpLogger.ts +++ b/js/plugins/google-cloud/src/gcpLogger.ts @@ -15,6 +15,7 @@ */ import { LoggingWinston } from '@google-cloud/logging-winston'; +import { getCurrentEnv } from 'genkit'; import { logger } from 'genkit/logging'; import { Writable } from 'stream'; import { GcpTelemetryConfig } from './types'; @@ -56,6 +57,7 @@ export class GcpLogger { prefix: 'genkit', logName: 'genkit_log', credentials: this.config.credentials, + autoRetry: true, defaultCallback: await this.getErrorHandler(), }) : new winston.transports.Console() @@ -90,6 +92,13 @@ export class GcpLogger { } else if (err) { defaultLogger.error(`Unable to send logs to Google Cloud: ${err}`); } + + if (err) { + // Assume the logger is compromised, and we need a new one + // Reinitialize the genkit logger with a new instance with the same config + logger.init(new GcpLogger(this.config).getLogger(getCurrentEnv())); + defaultLogger.info('Initialized a new GcpLogger.'); + } }; }