Closed OlenaHryshko closed 1 year ago
@OlenaHryshko thanks for your report. We can provide some defensive code but this also appears to be a bug with pino because it cannot properly stringify an object that has a "
in a key. Since pino manually builds serialization/de-serialization. If you do this in Node.js it just works
> JSON.stringify({ 'test"me': 'value'})
'{"test\\"me":"value"}'
> const a = JSON.stringify({ 'test"me': 'value'})
undefined
> JSON.parse(a)
{ 'test"me': 'value' }
>
@bizob2828 thanks for your response. Created an issue in pino lib. We'll see if it's possible to fix it there. As soon as this serializer is custom, I'd suggest adding some defensive code in any case. You never know what edge cases might occur.
@bizob2828 thank you for the notification
Description
Using newrelic to capture application logs + pino as a logger agent. While logging using pino, it is possible to pass mergingObject to add more context to the log. In case key(s) of the mergingObject contains
"
symbol, it is not getting shielded. So, logged object is not a JSON string, but newrelic lib tries to parse it to a JSON object.NewRelic throws an error below:
Expected Behavior
Handle JSON.parse error. In case it is not possible to parse JSON object from log string, save the whole log string as a message.
Troubleshooting or NR Diag results
As per comment in the code, newrelic calls pino asJson method. It returns invalid JSON string, which is getting passed into newrelic reformatLogLine method.
Steps to Reproduce
logger.info({'some"prop': {'details': true}})
. Code snippet:logger.info({'some"prop': {'details': true}});