Feature request: allow custom JSON replacer function
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.
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))
}
]
},
});
@TerryMooreII thanks. Wouldn't this defeat the purpose of using the fast serializer?
@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.