Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport closes before logs are shipped #44

Open
yaron-idan opened this issue Sep 4, 2020 · 5 comments
Open

Transport closes before logs are shipped #44

yaron-idan opened this issue Sep 4, 2020 · 5 comments
Labels
bug Something isn't working Hacktoberfest

Comments

@yaron-idan
Copy link
Contributor

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?

@JaniAnttonen
Copy link
Owner

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
Copy link
Owner

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 JaniAnttonen added bug Something isn't working Hacktoberfest labels Oct 1, 2020
@JaniAnttonen
Copy link
Owner

#51 might have fixed this?

@zabil
Copy link

zabil commented May 18, 2023

Hi, We see this issue where the logs are not completely shipped.

For reference here is the setup.

  logger = winston.createLogger({
    level,
    transports: [
      new LokiTransport({
        host: lokiHost,
        batching: false,
        format: json(),
        onConnectionError: (err) => console.error(err),
      }),
    ]
  });

 export default logger;

Usage in lambda

import log from "logger";

export const handler = async (event: S3ObjectEvent) => {
  log.info("Received S3 Notification event");
  // And other log events
}

We have noticed that not all the log statements are being sent, especially the ones at the end. We think this happens because the handler shuts down after the response.

Version info

    "node_modules/winston-loki": {
      "version": "6.0.6",
      "resolved": "https://registry.npmjs.org/winston-loki/-/winston-loki-6.0.6.tgz",
      ...

@rlfrahm
Copy link

rlfrahm commented Nov 14, 2023

I'm encountering this issue as well. I'm using this for scripts run by ts-node, so my workaround has been to wait for 5 seconds at the end of the script before process.exit(0). I'm not sure what to do for an API endpoint for instance yet. I see there are some options to pass in to the LokiTransport constructor like timeout and gracefulShutdown, as well as flush() available from the class, but I've not tested a combo that solves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants