Elixir bindings for Vector Remap Language.

Compile a program once with compile/1, then run it against many events with run/3. The full VRL standard library is available, except for network functions.

iex> {:ok, program} = VRL.compile(".message = upcase!(.message)")
iex> VRL.run(program, %{"message" => "hello"})
{:ok, %VRL.Result{value: "HELLO", event: %{"message" => "HELLO"}}}

Value conversion

ElixirVRL
binarystring
integer (64-bit)integer
floatfloat
true / falseboolean
nilnull
mapobject
listarray
DateTimetimestamp
other atomsstring

Map keys may be binaries or atoms; returned maps always have binary keys. Timestamps are returned as UTC DateTimes with microsecond precision. Other structs are passed as maps, keeping "__struct__" unless the :strip_structs option is set.

Integer overflow

VRL integer arithmetic (+, -, *) wraps around on 64-bit overflow without an error or warning. This is upstream VRL behaviour:

iex> {:ok, program} = VRL.compile("9223372036854775807 + 1")
iex> {:ok, %VRL.Result{value: value}} = VRL.run(program)
iex> value
-9223372036854775808

Summary

Functions

Compiles VRL source into a reusable VRL.Program.

Maximum nesting of maps and lists accepted by and returned from run/3.

Runs a compiled program against event.

Types

event()

@type event() :: term()

run_error()

@type run_error() :: String.t() | {:abort, String.t()}

Functions

compile(source)

@spec compile(String.t()) :: {:ok, VRL.Program.t()} | {:error, String.t()}

Compiles VRL source into a reusable VRL.Program.

Returns {:error, diagnostics} with human-readable diagnostics when the program is invalid.

max_depth()

@spec max_depth() :: pos_integer()

Maximum nesting of maps and lists accepted by and returned from run/3.

Deeper values return {:error, "maximum nesting depth of 128 exceeded"}.

run(program, event \\ %{}, opts \\ [])

@spec run(VRL.Program.t(), event(), keyword()) ::
  {:ok, VRL.Result.t()} | {:error, run_error() | :timeout}

Runs a compiled program against event.

Returns {:ok, %VRL.Result{}} with the program's resulting value and the transformed event. Returns {:error, {:abort, message}} when the program calls abort, and {:error, :timeout} when it exceeds the timeout.

Options

  • :timeout - maximum run time in milliseconds, or :infinity. Defaults to 5000. Checked between VRL expressions, so a single long-running function call can overrun it.
  • :strip_structs - when true, structs other than DateTime are passed as plain maps without the "__struct__" key. Defaults to false.