logdna / logdna-winston

LogDNA's Node.js logging module with support for Winston
MIT License
16 stars 14 forks source link

Application stalled when logging #5

Open AmicoJoules opened 6 years ago

AmicoJoules commented 6 years ago

Node version: 8.9.3

Configuration:

"logdna": {
        "index_meta": true,
        "key": "xxxxxxxxxxx",
        "env": "development" 
}

The first batch of logs is correctly sent and we can see them in the UI but after that the process just freezes and the CPU usage just rockets up.

AmicoJoules commented 6 years ago

The log that we sent and that is causing our app to freeze is

"response": {
    "statusCode": 200,
    "body": "\n{\"data\":{\"patName\":\"ALXXX\",\"patLastname\":\"CHXXX\",\"patSurename\":\"XXX\",\"patBdate\":\"19XX-XX-XX\",\"patGender\":\"X\",\"patEmail\":\"alXX@XXXX\",\"patTelephone\":\"+XXYYYYYY\",\"calle\":\"\",\"numeroCalle\":\"\",\"colonia\":\"\",\"delegacion\":\"\",\"cp\":\"\",\"ciudad\":\"\",\"dia\":\"XX\",\"mes\":\"XX\",\"anio\":\"19XX\",\"is_SDI\":\"No\",\"ultiLimpieza\":null},\"error\":\"\"}",
    "headers": {
      "date": "Mon, 03 Sep 2018 04:16:41 GMT",
      "server": "Apache",
      "vary": "Accept-Encoding",
      "content-length": "337",
      "connection": "close",
      "content-type": "text/html; charset=UTF-8"
    },
    "request": {
      "uri": {
        "protocol": "https:",
        "slashes": true,
        "auth": null,
        "host": "api.dentalia.com.mx",
        "port": 443,
        "hostname": "api.dentalia.com.mx",
        "hash": null,
        "search": "?api=xxxxx",
        "query": "api=xxxxx",
        "pathname": "/index.php",
        "path": "/index.php?api=xxxxxx",
        "href": "https://api.dentalia.com.mx/index.php?api=xxxxx"
      },
      "method": "POST",
      "headers": {
        "content-type": "multipart/form-data; boundary=--------------------------XXXXXXXXXXXXXX",
        "content-length": 437
      }
    }
  }
AmicoJoules commented 6 years ago

As you can see this is an API call and my guess is that the problem has something to do with how the body is formatted, that's why we had to do a JSON.stringify() and that fix the problem on our side but we are worried that any other API/call could potentially freeze our application as well. Is there anything on your side that can be done to minimize this risk?

LYHuang commented 6 years ago

Would you provide more information about how you send the log? I can't reproduce the issue you have.

Below is my setup, run perfectly for me.

var options = {
    key: apikey,
    hostname: 'some host',
    app: 'some app',
    index_meta: true
};
winston.add(winston.transports.Logdna, options);
winston.log('info', 'hi from logdna-winston node: 8.9.3', {yourLogObject});
DylanBowden commented 5 years ago

Hi, I have the same issue. I'm logging a request object and it's stalling. This is the code I have

logger.error({err, property: "data"});

I can get around it by either JSON.stringify() or not passing the err as part of an object, i.e.

logger.error(err, {property: "data"});

Note that the error is an instance of a request error (module request-promise) and has some functions in it

SirDeadlystrike commented 5 years ago

@DylanBowden this is usually caused by attempting to log an object that has recursive properties.

You will need to serialize the object/error first before passing it to logdna

I recommend the package serialize-error from npmjs.

You can wrap your error as such:

const serializeError = require('serialize-error');
logger.error("An error occured", { meta: { error: serializeError(err) } });