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

Winston throws 'Elasticsearch error' with no other information

Open rauldeheer opened this issue 1 year ago • 6 comments

Our application sometimes receives a Elasticsearch error from node_modules/winston-elasticsearch/bulk_writer.js and specifically on line 134:

.then((res) => {
      if (res && res.errors && res.items) {
        const err = new Error('Elasticsearch error');
        res.items.forEach((item, itemIndex) => {
          const bodyData = body[itemIndex * 2 + 1];

The error appears to be:

elasticsearch indexing error {
  type: 'mapper_parsing_exception',
  reason: 'object mapping for [fields.stack] tried to parse field [null] as object, but found a concrete value'
}

Why and when is such an error usually thrown and what can we do to fix this? This error actually causes our whole container to shut-down. We're using NestJS.

rauldeheer avatar Sep 07 '23 13:09 rauldeheer

Any news/information on this?

rauldeheer avatar Sep 22 '23 12:09 rauldeheer

I was eventually able to fix this error by just catching all errors in our NestJS application and mutating the error format. It took quite some while to figure out where the exception was actually coming from.

rauldeheer avatar Sep 22 '23 13:09 rauldeheer

It still throws this error occasionally. So this is still not fixed unfortunately.

rauldeheer avatar Oct 09 '23 13:10 rauldeheer

We also encounter some issues with this since some weeks on multiple Nest 9 repositories, multiple logs are sent and it seems to loop on it and then crash image image

Elio-FairlyMade avatar Dec 04 '23 21:12 Elio-FairlyMade

We eventually just disabled this package and our application never crashes again. Just waiting until it's fixed.

rauldeheer avatar Jan 05 '24 09:01 rauldeheer

This case is described in the documentation. I spent a few hours trying to fix this issue and then just realized that the app fails because I don't handle 'error' events for elastic transport and logger instances.

...
  if (config.log.useElasticTransport) {
    const elasticsearchTransport = new ElasticsearchTransport({
      ...
    });
    elasticsearchTransport.on('error', console.error);

    transports.push(elasticsearchTransport);
  }

  const instance = winston.createLogger({
    transports,
  });
  instance.on('error', console.error);

  return WinstonModule.createLogger({
    instance,
  });

So, to summarise, for the Nest.js application you need:

  1. Create Elacticsearch transport and add an error event listener;
  2. Create an instant of a Winston logger and pass transport inside;
  3. Add an error event listener to the logger instance;

Hope this information will be helpful.

vladpartida avatar Jun 18 '24 10:06 vladpartida