Join us from October 8-10 in New York City to learn the latest tips, trends, and news about GraphQL federation and API platform engineering.Join us for GraphQL Summit 2024 in NYC
Docs
Start for Free

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:

router.yaml
telemetry:
instrumentation:
instruments:
router:
my.instrument:
value: duration
type: counter
unit: s
description: "my description"
# ...
# This instrument will only be mutated if the condition evaluates to true
condition:
all:
- any:
- eq:
- "val"
- request_header: x-req-header
- eq:
- "foo"
- 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:

exists:
- 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:

eq:
- "val"
- request_header: x-req-header

You can use selectors on both sides of the equality test:

eq:
- request_header: x-req-header1
- 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:

gt:
- response_status: code
- 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:

lt:
- response_status: code
- 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:

not:
eq:
- "val1"
- 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:

all:
- eq:
- "val1"
- request_header: x-req-header1
- eq:
- "val2"
- 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:

any:
- eq:
- "val2"
- request_header: x-req-header1
- eq:
- "val2"
- request_header: x-req-header2

Condition configuration reference

The available basic conditions:

ConditionDescription
eqAn equality test between selectors or values
gtAn inequality test between selectors or values
ltAn inequality test between selectors or values
existA check to see if the selectors value exists
notA negated equality test between selectors or values
allA list of conditions that must all be true
anyA list of conditions of which at least one must be true

You can create complex conditions by using these basic conditions as building blocks.

Previous
Events
Next
Spans
Rate articleRateEdit on GitHubEditForumsDiscord

© 2024 Apollo Graph Inc.

Privacy Policy

Company