EDXCoalesce
2 minute read
Minimum Agent Version: v2.0.0
EDXCoalesce fills a gap in standard OTTL which lacks null coalescing capabilities. While OTTL can check for null values with IsMatch, it doesn’t provide an elegant way to select the first non-null value from multiple options. This Edge Delta extension works like the null coalescing operator (??) in modern languages, enabling graceful handling of missing or empty fields with a fallback value.
Syntax
EDXCoalesce(value, fallback)
value: The primary value or field reference to evaluate.fallback: The fallback value or field reference to return if the primary value is null, empty, or zero.
For more than two values, nest multiple EDXCoalesce calls:
EDXCoalesce(value1, EDXCoalesce(value2, EDXCoalesce(value3, defaultValue)))
Input
{
"_type": "log",
"timestamp": 1735789600000,
"body": "User activity log",
"resource": {...},
"attributes": {
"user_id": null,
"session_id": "",
"tracking_id": "track-12345",
"primary_email": null,
"secondary_email": "",
"fallback_email": "default@example.com",
"error_message": "",
"warning_message": null,
"info_message": "Operation completed"
}
}
Example
set(attributes["effective_id"], EDXCoalesce(attributes["user_id"], EDXCoalesce(attributes["session_id"], EDXCoalesce(attributes["tracking_id"], "anonymous"))))
set(attributes["contact_email"], EDXCoalesce(attributes["primary_email"], EDXCoalesce(attributes["secondary_email"], attributes["fallback_email"])))
set(attributes["log_message"], EDXCoalesce(attributes["error_message"], EDXCoalesce(attributes["warning_message"], EDXCoalesce(attributes["info_message"], "No message"))))
Output
{
"_type": "log",
"timestamp": 1735789630000,
"body": "User activity log",
"resource": {...},
"attributes": {
"user_id": null,
"session_id": "",
"tracking_id": "track-12345",
"primary_email": null,
"secondary_email": "",
"fallback_email": "default@example.com",
"error_message": "",
"warning_message": null,
"info_message": "Operation completed",
"effective_id": "track-12345",
"contact_email": "default@example.com",
"log_message": "Operation completed"
}
}
The EDXCoalesce function has selected the first non-null/non-empty value for each field: “track-12345” for the effective ID (skipping null user_id and empty session_id), “default@example.com” for the contact email (after checking primary and secondary), and “Operation completed” for the log message (after checking error and warning messages).