Caution
Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.
Operators
River uses a common set of operators. All operations follow the standard PEMDAS order of mathematical operations.
Arithmetic operators
String operators
Comparison operators
You can apply the equality operators ==
and !=
to any operands.
The two operands in ordering operators <
<=
>
and >=
must both be orderable and of the same type.
The results of the comparisons are:
- Boolean values are equal if they’re either both true or both false.
- Numerical (integer and floating-point) values are orderable in the usual way.
- String values are orderable lexically byte-wise.
- Objects are equal if all their fields are equal.
- Array values are equal if their corresponding elements are equal.
Logical operators
Logical operators apply to boolean values and yield a boolean result.
Assignment operator
River uses =
as its assignment operator.
An assignment statement may only assign a single value. Each value must be assignable to the attribute or object key.
- You can assign
null
to any attribute. - You can assign numerical, string, boolean, array, function, capsule, and object types to attributes of the corresponding type.
- You can assign numbers to string attributes with an implicit conversion.
- You can assign strings to numerical attributes if they represent a number.
- You can’t assign blocks.
Brackets
The following example uses curly braces and square brackets to define an object and an array.
obj = { app = "agent", namespace = "dev" }
arr = [1, true, 7 * (1+1), 3]
Access operators
You can access arbitrarily nested values with River’s access operators. You can use square brackets to access zero-indexed array indices and object fields by enclosing the field name in double quotes. You can use the dot operator to access object fields without double quotes and component exports.
obj["app"]
arr[1]
obj.app
local.file.token.content
If you use the [ ]
operator to access a member of an object where the member doesn’t exist, the resulting value is null
.
If you use the .
operator to access a named member of an object where the named member doesn’t exist, an error is generated.