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

unsafe stringify and JSON circular structure

Open nitzan-blink opened this issue 9 months ago • 0 comments

Hi, if I pass an axios error object to the transport's .error() function, the logger crashes with the following exception:

2024-05-05 09:59:11.394  Error: app logged out: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'httpAgent' -> object with constructor 'Agent'
    |     property 'sockets' -> object with constructor 'Object'
    |     ...
    |     property 'errored' -> object with constructor 'Object'
    --- property 'config' closes the circle
2024-05-05 09:59:11.397  TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'httpAgent' -> object with constructor 'Agent'
    |     property 'sockets' -> object with constructor 'Object'
    |     ...
    |     property 'errored' -> object with constructor 'Object'
    --- property 'config' closes the circle
    at JSON.stringify (<anonymous>)
    at LogstashTransport.log (/app/node_modules/.pnpm/[email protected][email protected]/node_modules/winston-logstash/lib/winston-logstash-latest.js:34:27)
    at LogstashTransport._write (/app/node_modules/.pnpm/[email protected]/node_modules/winston-transport/index.js:82:19)
    at doWrite (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:390:139)
    at writeOrBuffer (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:381:5)
    at Writable.write (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_writable.js:302:11)
    at DerivedLogger.ondata (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js:629:20)
    at DerivedLogger.emit (node:events:529:35)
    at addChunk (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js:279:12)
    at readableAddChunk (/app/node_modules/.pnpm/[email protected]/node_modules/readable-stream/lib/_stream_readable.js:262:11)

a related issue is: https://github.com/winstonjs/winston/issues/1946 where it was suggested that fast-safe-stringify should be used instead of JSON.stringify(). in the code I see several refernces to stringify libs, but they are all in the test bench.

nitzan-blink avatar May 05 '24 13:05 nitzan-blink