winston-loki icon indicating copy to clipboard operation
winston-loki copied to clipboard

Transport closes before logs are shipped

Open yaron-idan opened this issue 3 years ago • 5 comments

I'm trying to use this transport in an AWS Lambda function and I'm finding that the function terminates before the logs are shipped to Loki. I've noticed this issue in Winston's main repository and tried to implement this workaround in order to force the function to wait for the logger to finish shipping the logs but it does not wait for the requests to be sent before resolving the promise and closing the function.

I suspect it has something to do with this line which immediately emits a logged event to winston instead of waiting for the log record to be pushed, but honestly I feel I'm not familiar enough with Winston to be sure this is exactly what's happening.

Could emitting the logged event further down the line help with the scenario I've presented?

yaron-idan avatar Sep 04 '20 17:09 yaron-idan

Nice find. Might want to take a closer look at the events winston listens to. I'll come back at you, but you're welcome to submit a solution if you find one :)

JaniAnttonen avatar Sep 06 '20 09:09 JaniAnttonen

It is a bit weird though, if the logged event firing is the culprit. The index.js structure is based on https://github.com/winstonjs/winston/blob/bc6a363ec9164d03f266cab7c918d92208d2ec73/examples/custom-transport.js, that's why the logged event gets fired before the transport. Are you using batching or sending out logs as they come? Does changing that option change things?

JaniAnttonen avatar Sep 08 '20 09:09 JaniAnttonen

#51 might have fixed this?

JaniAnttonen avatar Nov 01 '20 20:11 JaniAnttonen