bragma / winston-azure-application-insights

Azure Application Insights transport for Winston
MIT License
16 stars 26 forks source link

Support formatting of metadata, including 'flat' builtin #5

Open glenjamin opened 7 years ago

glenjamin commented 7 years ago

Thanks for making this module, it was really easy to get our logs into app insights from our existing winston logs.

One thing we discovered was that our log metadata sometimes contained nested objects, and this isn't supported by app insights - all properties get toStringed with this helper function https://github.com/Microsoft/ApplicationInsights-node.js/blob/develop/Library/Util.ts#L134-L160

This PR adds the ability to pre-format all messages before they go to azure, and provides a built-in "flat" formatter which attempts to do something sensible for nested objects. The default is left unchanged so as not to break backwards compatibility.

I tried to follow the existing code style, hope this makes sense!

bragma commented 7 years ago

Thanks for the PR, I'll give it a look!

bragma commented 7 years ago

Hi @glenjamin, I've imported the PR in the devel mainline and added some basic configuration for the default flattening function you implemented. Can you give it a look? It should preserve what you did and add some very basic protection against reference cycles (which caused a stack boom due to recursion). Thanks!

glenjamin commented 7 years ago

LGTM, the repetition for the recursive function was bugging me too, so good to see you removed that!

It's worth noting that winston's built-in JSON mode has no cycle protection, but what you've done here looks sensible and low-cost.

willmorgan commented 6 years ago

This is helpful and has a related issue on the AI Node SDK: https://github.com/Microsoft/ApplicationInsights-node.js/issues/371

Switched base branch to 1.1 for better merge visualisation.