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

Javascript enrichment should write to logs via slf4j #776

Open
istreeter opened this issue Apr 19, 2023 · 0 comments
Open

Javascript enrichment should write to logs via slf4j #776

istreeter opened this issue Apr 19, 2023 · 0 comments

Comments

@istreeter
Copy link
Contributor

For debugging purposes, someone might choose to add some print statements to their custom javascript enrichment:

function process(event) {
  const ipAddress = event.getUser_ipaddress
  print(ipAddress)
  return []
}

There are a couple of problems with this:

  • If the print statement runs on every event, it could send a HUGE amount of text to the logs.
  • We should avoid logging event data in production, because of PII. The example above logs the user's IP address, which would be bad.

The nashorn engine lets us capture the stdout from the enrichment and redirect it to a string. We could log this string using slf4j at debug level. This means users can add print lines for development, with logging turned on a debug level. But with production settings the debug lines do not appear in the logs.

Something like....

val sw = new StringWriter()
val context = engine.getContext()
context.setWriter(sw)
context.setErrorWriter(sw)
engine.invokeFunction(.....)
slf4jLogger.debug(sw.toString)

(that's completely untested)

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

1 participant