Skip to main content

Description

This Processor enables you to use a subset of JavaScript to transform your data, which can significantly simplify your Pipeline map.You can combine multiple actions like filtering, dropping, mapping, and casting inside of a single script.
This processor has specific limitations on command execution, as described in the section on Known Limitations.

Configuration

Main Function

With the JavaScript processor you can define a single function to encapsulate the logic for processing an event. This function can be named whatever you want, but by default is called processEvent. This function has up to three arguments that you can declare positionally, by any name. The function must return a value on all paths. The returned object (modified, replaced, or otherwise) becomes the message downstream. Returning null causes the message to be dropped (no event is propagated). Modified metadata is propagated with the message.

Global Functions

These functions are available to use on any respective value. At this time, these are the only supported global operations. There is no support for global objects like Math, Array, Map, or Set, except for Object, JSON and Date objects.

Comparison Operators

This processor supports all basic comparison operators that are defined in JavaScript.

Arithmetic Operators

An arithmetic operator takes numerical values as their operands and returns a single numerical value.

String Operations

String operations supported follow the standard JavaScript conventions.

Function-Scoped Variables

Variables can be defined and used inside of the main processEvent function. To use one, define a variable with the let keyword.

Deleting Attributes

Attributes can be deleted from an object by assigning undefined .

Examples

Filter Events

Adding Properties to an Event

Removing Properties from an Event

Parsing Numbers

Convert To String

Counting the Number of Bytes in a Message

This example shows how you can compute the size of the event payload using combined functions. This returns the amount of the size in bytes by assuming that each character is 1 byte (8 bit ASCII characters).

Working with Strings

Working with Arrays

Known Limitations

This processor was not intended to implement the full JavaScript language, but was developed with event manipulation in mind only. For this reason, it has some limitations:
  • Only one function can be used to encapsulate all of the logic (helper functions aren’t supported)
  • Accessing Array items is only supported with literal values (numbers)
  • Only JavaScript ES5 syntax is supported
  • Error handling is not supported via try/catch
  • Mixing data types with binary expressions results in a no-op