EDXIfElse
2 minute read
Minimum Agent Version: v2.0.0
EDXIfElse fills a gap in standard OTTL which lacks inline conditional operators. While OTTL supports conditional logic with where clauses for conditional execution of entire statements, it doesn’t provide a ternary operator for conditional value assignment within a single statement. This Edge Delta extension enables you to choose between two values based on a condition, similar to the ternary operator (? :) in many programming languages.
Syntax
EDXIfElse(condition, value_if_true, value_if_false)
condition: A boolean expression or field that evaluates to true or false.value_if_true: The value to return if the condition is true.value_if_false: The value to return if the condition is false.
Input
{
"_type": "log",
"timestamp": 1735789500000,
"body": "Transaction processed",
"resource": {...},
"attributes": {
"transaction_amount": 150,
"user_type": "premium",
"is_weekend": true,
"error_count": 0
}
}
Example
set(attributes["transaction_size"], EDXIfElse(attributes["transaction_amount"] > 100, "large", "small"))
set(attributes["discount_eligible"], EDXIfElse(attributes["user_type"] == "premium", true, false))
set(attributes["processing_mode"], EDXIfElse(attributes["is_weekend"], "batch", "realtime"))
set(attributes["status"], EDXIfElse(attributes["error_count"] > 0, "failed", "success"))
Output
{
"_type": "log",
"timestamp": 1735789530000,
"body": "Transaction processed",
"resource": {...},
"attributes": {
"transaction_amount": 150,
"user_type": "premium",
"is_weekend": true,
"error_count": 0,
"transaction_size": "large",
"discount_eligible": true,
"processing_mode": "batch",
"status": "success"
}
}
The EDXIfElse function has evaluated each condition and assigned the appropriate values: “large” for transaction size (amount > 100), true for discount eligibility (premium user), “batch” for processing mode (weekend), and “success” for status (no errors).