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

Feature request: allow custom JSON replacer function #46

Open
rfink opened this issue Jul 15, 2022 · 3 comments
Open

Feature request: allow custom JSON replacer function #46

rfink opened this issue Jul 15, 2022 · 3 comments

Comments

@rfink
Copy link

rfink commented Jul 15, 2022

Allow custom JSON replacer function to be passed in via options, which will allow us to sanitize sensitive data from the logs (passwords, cc info, etc), helpful if objects passed into meta. Pull request incoming.

@TerryMooreII
Copy link
Collaborator

This should be able to be accomplished by adding a custom beforeSend hook.

This will parse both the message and the lineContext

const jsonReplacer = (key, value) => {
  if (key === 'password') {
    return '[redacted]';
  }
  return value;
};

logdna.init('ingestionkey', {
  hooks: {
      beforeSend: [
        (line) => {
          return JSON.parse(JSON.stringify(line, jsonReplacer))
        }
      ]
    },
});

@rfink
Copy link
Author

rfink commented Jul 15, 2022

@TerryMooreII thanks. Wouldn't this defeat the purpose of using the fast serializer?

@TerryMooreII
Copy link
Collaborator

@rfink True, you could require/import fast-safe-stringify or any other stringify package and use it in your hook. We mostly use fast-safe-stringify because of its circular reference detection.

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

No branches or pull requests

2 participants