@@ -96,6 +96,7 @@ export class PinoCloudExporter {
9696 private readonly batchSize : number ;
9797 private readonly flushIntervalMs : number ;
9898 private jwt : string | null = null ;
99+ private jwtExpiresAt = 0 ;
99100 private pendingLogs : any [ ] = [ ] ;
100101 private flushTimer : NodeJS . Timeout | null = null ;
101102
@@ -172,6 +173,9 @@ export class PinoCloudExporter {
172173 await this . sendLogs ( logs ) ;
173174 } catch ( error ) {
174175 this . pendingLogs = [ ...logs , ...this . pendingLogs ] ;
176+ if ( this . pendingLogs . length > 10000 ) {
177+ this . pendingLogs = this . pendingLogs . slice ( - 10000 ) ;
178+ }
175179 console . error ( '[PinoCloudExporter] Failed to flush logs:' , error ) ;
176180 }
177181 }
@@ -223,7 +227,7 @@ export class PinoCloudExporter {
223227 }
224228
225229 private async ensureJwt ( ) : Promise < void > {
226- if ( this . jwt ) return ;
230+ if ( this . jwt && Date . now ( ) < this . jwtExpiresAt ) return ;
227231
228232 const apiKey = process . env . LIVEKIT_API_KEY ;
229233 const apiSecret = process . env . LIVEKIT_API_SECRET ;
@@ -235,6 +239,7 @@ export class PinoCloudExporter {
235239 const token = new AccessToken ( apiKey , apiSecret , { ttl : '6h' } ) ;
236240 token . addObservabilityGrant ( { write : true } ) ;
237241 this . jwt = await token . toJwt ( ) ;
242+ this . jwtExpiresAt = Date . now ( ) + 5 * 60 * 60 * 1000 ;
238243 }
239244
240245 async shutdown ( ) : Promise < void > {
0 commit comments