Transform with JavaScript

Transform logs based on a JavaScript function.


This filter type uses Goja (a type of script in JavaScript) to transform specified log messages. When a log matches the criteria, it will be transformed, and then passed through the filter.

Review Sample Configuration

Review the following sample configuration:

- name:  add_json_field
  type: log-transformer-javascript
  script: |
    var obj = JSON.parse(log);
    obj.version = "latest";
    log = JSON.stringify(obj);    
  keep_log_if_failed: true




Enter a descriptive name for this filter.

When you create a workflow, you will use this label to enter your filter into the workflow.

Review the following example:

name: all_add_json_field



Enter log-transformer-javascript.

Review the following example:

type: log-transformer-javascript


Required Define a script to transform matching logs. After a matched log has been transformed, it will pass through the filter.

In the script, you must set the raw log variable to log.

Review the following example:

script: |
  var obj = JSON.parse(log)
  obj.version = "latest"
  log = JSON.stringify(obj)  

Based on the above example, the first log line will be transformed into the second log line:

{"app": "alpine", "service": "nonprod", "source": "tomcat"}
{"app": "alpine", "service": "nonprod", "source": "tomcat", "version": "latest"}



The keep_log_if_failed parameter defines how to handle an error when processing the filter. It is defined with a Boolean value true or false. The default value is false indicating that the filter will drop or ignore logs that caused an error. The keep_log_if_failed parameter is optional.

  - name: <filter-name>
    type: <filter-type>
    keep_log_if_failed: <true|false>