winston-azure-application-insights icon indicating copy to clipboard operation
winston-azure-application-insights copied to clipboard

Support formatting of metadata, including 'flat' builtin

Open glenjamin opened this issue 7 years ago • 4 comments

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!

glenjamin avatar Apr 01 '17 12:04 glenjamin

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

bragma avatar Apr 05 '17 16:04 bragma

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!

bragma avatar Apr 06 '17 11:04 bragma

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.

glenjamin avatar Apr 07 '17 06:04 glenjamin

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.

willmorgan avatar Mar 01 '18 14:03 willmorgan