Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: 1.1
Choose a base branch
from

Conversation

glenjamin
Copy link

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!

Flat is useful as application insights doesn't allow nested properties,
its left as an option so as not to break backwards compatibility
@bragma
Copy link
Owner

bragma commented Apr 5, 2017

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

@bragma
Copy link
Owner

bragma commented Apr 6, 2017

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
Copy link
Author

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 willmorgan changed the base branch from master to 1.1 March 1, 2018 14:45
@willmorgan
Copy link
Collaborator

willmorgan commented Mar 1, 2018

This is helpful and has a related issue on the AI Node SDK: microsoft/ApplicationInsights-node.js#371

Switched base branch to 1.1 for better merge visualisation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants