Open cuzzlor opened 2 months ago
@cuzzlor thanks for the details, you should be able to take care of the issue without patching the code using a LogProcessor and formatting the error attributes, I'm wondering how often most people will see Errors as part of LogRecords, can you describe the actual way you are using Winston that generated the problem here?
Hi @hectorhdzg
I noticed our error logs were missing error details when including an error in the log function arguments:
logger.error('this went wrong', {blah, error})
In this case, blah
comes out in the logs, error
gets dropped.
Hi! 👋
Firstly, thanks for your work on this project! 🙂
Today I used patch-package to patch
@azure/monitor-opentelemetry@1.6.0
for the project I'm working on.My problem is that logRecord attributes that are
instanceof Error
are not serialized in a way that preserves themessage
andstack
props.JSON.stringify(new Error('hello'))
produces{}
JSON.stringify
is used without a replacer that can enumerate themessage
andstack
props of an Error, because they are not enumerable (because JS).https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/monitor/monitor-opentelemetry/src/logs/batchLogRecordProcessor.ts#L35
In the patch below we are importing our own replacer with the very simple structure which simply spreads the
message
,stack
and other props of the error: https://github.com/MakerXStudio/node-winston/blob/main/src/serialize-error.tsHere is the diff that solved my problem:
This issue body was partially generated by patch-package.