Edge Delta Transform with JavaScript Filter

Transform logs based on a JavaScript function.

Overview

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

Parameters

name

Required

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

type

Required

Enter log-transformer-javascript.

Review the following example:

type: log-transformer-javascript

script

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 this 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"}

keep_log_if_failed

Optional 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.

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