You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am facing an issue using sync: true in my Pino multi transport configuration within an AWS Lambda function.
According to the Pino documentation, setting sync: true should make the transport operate synchronously. However, this does not seem to work as expected in my setup. Additionally, logs are not appearing correctly in CloudWatch or SQS, depending on the transport used.
Here’s the configuration I’m using for my transports:
importpino,{DestinationStream,TransportTargetOptions}from'pino';import{ILoggerTransportStrategy}from'../interfaces/transport-strategy.interface';importconfigfrom'../../../../../../config/config';import{TransportOptions}from'../../options/options';import{GeneralTransportOptionsType,TransportOptionsType}from'../../../../../common';/** * Clase que se encarga de configurar los transportes de logs */exportclassMultiTransportStrategyimplementsILoggerTransportStrategy{privatetargets: TransportTargetOptions[];constructor(){this.targets=[];}/** * Configura los transportes de logs * @param options - Opciones de configuración * @returns - El destino de los logs */configure(options: GeneralTransportOptionsType): DestinationStream{consttargets: TransportOptionsType[]=config.get('log.targets')asTransportOptionsType[];if(targets.length===0){returnpino.transport({targets: [TransportOptions.select('cloud',options)],});}for(consttargetoftargets){this.addTransport(TransportOptions.select(target,options));}consttransports=pino.transport({targets: this.targets,sync: true,});this.targets=[];returntransports;}/** * Añade un transporte a la lista de transportes * @param transport - Transporte a añadir */privateaddTransport(transport: TransportTargetOptions): void{if(transport===null||transport===undefined){return;}this.targets.push(transport);}}
/** * - Opciones de transporte para la consola estándar. * @returns TransportSingleOptions */exportconstcloudTargetOptions=(): TransportTargetOptions=>{return{level: config.get('log.level'),target: 'pino/file',options: {destination: 1,},};};
importbuild,{OnUnknown}from'pino-abstract-transport';import{SQSClient,SQSClientConfig,SendMessageCommand,SendMessageRequest}from'@aws-sdk/client-sqs';/** * Opciones de configuración para el transporte SQS. */exporttypeSQSTransportOptionsType={region?: string;queueUrl: string;messageGroupId?: string;sqsOptions?: SQSClientConfig;};/** * - Transporte personalizado para enviar logs a una cola de SQS * @param opts - Opciones de configuración * @returns - Función que recibe un objeto y lo envía a la cola de SQS */exportdefaultasyncfunction(opts: SQSTransportOptionsType): Promise<OnUnknown>{const{ region ='us-east-1', queueUrl, messageGroupId, sqsOptions }=opts;constsqsClient=newSQSClient({ region, ...sqsOptions});returnbuild(asyncfunction(source){forawait(constobjofsource){constlogMessage=JSON.stringify({message: JSON.stringify(obj)});constparams: SendMessageRequest={QueueUrl: queueUrl,MessageBody: logMessage,MessageGroupId: messageGroupId,};try{constcommand=newSendMessageCommand(params);awaitsqsClient.send(command);}catch(error){console.error('Error al enviar el mensaje a SQS:',error);}}});}
Expected Behavior
The sync: true option should ensure synchronous operation for the transports in AWS Lambda.
Logs should appear in the destinations (e.g., SQS or CloudWatch) during the Lambda invocation.
--
Actual Behavior
The sync: true option does not make the transports synchronous.
Logs are not visible in SQS or CloudWatch.
The text was updated successfully, but these errors were encountered:
Hi, I am facing an issue using sync: true in my Pino multi transport configuration within an AWS Lambda function.
According to the Pino documentation, setting sync: true should make the transport operate synchronously. However, this does not seem to work as expected in my setup. Additionally, logs are not appearing correctly in CloudWatch or SQS, depending on the transport used.
Here’s the configuration I’m using for my transports:
Expected Behavior
The sync: true option should ensure synchronous operation for the transports in AWS Lambda.
Logs should appear in the destinations (e.g., SQS or CloudWatch) during the Lambda invocation.
--
Actual Behavior
The sync: true option does not make the transports synchronous.
Logs are not visible in SQS or CloudWatch.
The text was updated successfully, but these errors were encountered: