Conditions
Set conditions for when events or instruments are triggered
You can set conditions for when an instrument should be mutated or an event should be triggered.
Condition configuration
Here is an example of a condition on a custom instrument:
1telemetry:
2 instrumentation:
3 instruments:
4 router:
5 my.instrument:
6 value: duration
7 type: counter
8 unit: s
9 description: "my description"
10 # ...
11 # This instrument will only be mutated if the condition evaluates to true
12 condition:
13 all:
14 - any:
15 - eq:
16 - "val"
17 - request_header: x-req-header
18 - eq:
19 - "foo"
20 - response_header: x-resp-header
exists
The exists
condition is testing if selectors is present.
For example, the following condition checks the value of x-req-header
exists:
1exists:
2 request_header: x-req-header
eq
The eq
condition is an equality test between selectors or values.
For example, the following condition checks the value of x-req-header
is equal to val
:
1eq:
2 - "val"
3 - request_header: x-req-header
You can use selectors on both sides of the equality test:
1eq:
2 - request_header: x-req-header1
3 - request_header: x-req-header2
Values may be of types string
, number
or boolean
.
gt
The gt
condition checks that one value is greater than another.
For example, the following condition checks the response status code is greater than 299:
1gt:
2 - response_status: code
3 - 299
Values may be of types string
, number
or boolean
.
lt
The lt
condition checks that one value is less than another.
For example, the following condition checks the response status code is less than 500:
1lt:
2 - response_status: code
3 - 500
Values may be of types string
, number
or boolean
.
not
The not
condition is a negation of the nested condition.
For example, the following condition checks the value of x-req-header
is not equal to val1
:
1not:
2 eq:
3 - "val1"
4 - request_header: x-req-header2
all
The all
condition is a list of conditions that all must be true in order for the condition to be true.
For example, the following all
condition has a list of eq
conditions that check the values of x-req-header1
and x-req-header2
, and both eq
conditions must be true in order for the all
condition to be true:
1all:
2 - eq:
3 - "val1"
4 - request_header: x-req-header1
5 - eq:
6 - "val2"
7 - request_header: x-req-header2
any
The any
condition is a list of conditions of which at least one must be true for the condition to be true.
For example, the following any
condition has a list of eq
conditions that check the values of x-req-header1
and x-req-header2
, and at least one of the eq
conditions must be true in order for the all
condition to be true:
1any:
2 - eq:
3 - "val2"
4 - request_header: x-req-header1
5 - eq:
6 - "val2"
7 - request_header: x-req-header2
Condition configuration reference
The available basic conditions:
Condition | Description |
---|---|
eq | An equality test between selectors or values |
gt | An inequality test between selectors or values |
lt | An inequality test between selectors or values |
exists | A check to see if the selectors value exists |
not | A negated equality test between selectors or values |
all | A list of conditions that must all be true |
any | A list of conditions of which at least one must be true |
You can create complex conditions by using these basic conditions as building blocks.