OTTL Quick Reference

Quick reference guide for OTTL syntax, operators, functions, and common patterns in Edge Delta telemetry pipelines.

Statement Syntax

function(target, arguments) where condition

Components:

  • function: Editor or converter function name
  • target: Field path using bracket notation
  • arguments: Values, paths, or nested functions
  • where: Optional condition for conditional execution

Path Notation

PathDescriptionExample
bodyLog body (byte array)Decode(body, "utf-8")
attributes["key"]Attribute fieldattributes["user_id"]
attributes["nested"]["key"]Nested attributeattributes["http"]["status"]
resource["key"]Resource fieldresource["k8s.namespace.name"]
cache["key"]Temporary storagecache["parsed_body"]
timestampLog timestamp (UnixMilli)set(timestamp, UnixMilli(Now()))
severity_textSeverity stringset(severity_text, "ERROR")

Operators

Comparison Operators

OperatorDescriptionExample
==Equalattributes["status"] == "error"
!=Not equalattributes["level"] != "debug"
>Greater thanattributes["count"] > 100
<Less thanattributes["score"] < 50
>=Greater or equalattributes["threshold"] >= 90
<=Less or equalattributes["retries"] <= 3

Logical Operators

Critical: Use lowercase and, or, not. Uppercase causes errors.

OperatorDescriptionExample
andBoth truea == 1 and b == 2
orEither truea == 1 or a == 2
notNegationnot IsMatch(a, "test")

Editor Functions (Modify Data)

Field Operations

FunctionSyntaxPurpose
setset(target, value)Set field value
delete_keydelete_key(map, "key")Remove single key
delete_matching_keysdelete_matching_keys(map, "regex")Remove matching keys
keep_keyskeep_keys(map, ["k1", "k2"])Keep only listed keys
keep_matching_keyskeep_matching_keys(map, "regex")Keep matching keys

Array Operations

FunctionSyntaxPurpose
appendappend(target, value)Add to array
limitlimit(map, count, ["priority"])Limit map size

String Operations

FunctionSyntaxPurpose
replace_matchreplace_match(target, pattern, replacement)Replace exact match
replace_patternreplace_pattern(target, regex, replacement)Replace regex match
replace_all_matchesreplace_all_matches(map, pattern, replacement)Replace in all values
replace_all_patternsreplace_all_patterns(map, regex, replacement)Regex replace in all
truncate_alltruncate_all(map, maxLen)Truncate all values

Map Operations

FunctionSyntaxPurpose
merge_mapsmerge_maps(target, source, "strategy")Merge maps
flattenflatten(map, "prefix", depth)Flatten nested map

Converter Functions (Transform Values)

String Functions

FunctionSyntaxReturns
ConcatConcat([val1, val2], sep)Joined string
ConvertCaseConvertCase(str, "upper/lower/snake/camel")Converted string
SplitSplit(str, delimiter)String array
SubstringSubstring(str, start, length)Substring
TrimTrim(str)Trimmed string
DecodeDecode(bytes, "utf-8")String from bytes
LenLen(str)Integer length
HasPrefixHasPrefix(str, "prefix")Boolean
HasSuffixHasSuffix(str, "suffix")Boolean

Pattern Functions

FunctionSyntaxReturns
IsMatchIsMatch(str, "regex")Boolean
ExtractPatternsExtractPatterns(str, "(?P<name>...)")Map of captures
ExtractGrokPatternsExtractGrokPatterns(str, "%{PATTERN:name}")Map of captures

Parsing Functions

FunctionSyntaxReturns
ParseJSONParseJSON(str)Map/any
ParseKeyValueParseKeyValue(str, "=", " ")Map
ParseCSVParseCSV(str)String array
ParseXMLParseXML(str)Map
ParseIntParseInt(str, base)Integer

Type Conversion

FunctionSyntaxReturns
StringString(value)String
IntInt(value)Integer
DoubleDouble(value)Float
IsStringIsString(value)Boolean
IsIntIsInt(value)Boolean
IsDoubleIsDouble(value)Boolean
IsMapIsMap(value)Boolean
IsListIsList(value)Boolean
IsBoolIsBool(value)Boolean

Hash Functions

FunctionSyntaxReturns
SHA256SHA256(str)Hash string
SHA1SHA1(str)Hash string
MD5MD5(str)Hash string
FNVFNV(str)Hash integer
Murmur3Murmur3(str)Hash integer

Time Functions

FunctionSyntaxReturns
NowNow()Current time.Time
TimeTime(str, format)Parsed time.Time
UnixMilliUnixMilli(time)Int64 milliseconds
DurationDuration(str)time.Duration
TruncateTimeTruncateTime(time, duration)Truncated time
YearYear(time)Integer
MonthMonth(time)Integer
DayDay(time)Integer
HourHour(time)Integer
MinuteMinute(time)Integer
SecondSecond(time)Integer

Collection Functions

FunctionSyntaxReturns
LenLen(collection)Integer count
KeysKeys(map)Key array
ValuesValues(map)Value array
SortSort(array, order)Sorted array
IndexIndex(array, idx)Element at index
ContainsValueContainsValue(map, value)Boolean

Utility Functions

FunctionSyntaxReturns
FormatFormat(template, [args])Formatted string
UUIDUUID()UUID string
HexHex(bytes)Hex string
URLURL(str)URL components map
UserAgentUserAgent(str)UA components map

Edge Delta Custom Functions

FunctionSyntaxPurpose
EDXEncodeEDXEncode(str, "utf-8")Encode to bytes
EDXIfElseEDXIfElse(cond, true_val, false_val)Ternary expression
EDXCoalesceEDXCoalesce(val1, val2, ...)First non-nil value
EDXLookupEDXLookup(table, key)Lookup table query
EDXEncryptEDXEncrypt(str, key)Encrypt value
EDXDecryptEDXDecrypt(str, key)Decrypt value
EDXParseKeyValueEDXParseKeyValue(str, opts)Advanced KV parsing
edx_codeedx_code(attributes, "script")JavaScript execution
edx_delete_keysedx_delete_keys(map, ["k1", "k2"])Delete multiple keys
edx_keep_keysedx_keep_keys(map, ["k1", "k2"])Keep multiple keys
edx_delete_matching_keysedx_delete_matching_keys(map, "regex")Delete by pattern
edx_keep_matching_keysedx_keep_matching_keys(map, "regex")Keep by pattern
edx_delete_empty_valuesedx_delete_empty_values(map)Remove empty fields
edx_map_keysedx_map_keys(map, mapping)Rename keys

Common Patterns

Decode and Parse JSON Body

set(cache["body"], Decode(body, "utf-8"))
set(cache["json"], ParseJSON(cache["body"]))
set(attributes["field"], cache["json"]["field"])

Extract with Regex

set(attributes, ExtractPatterns(Decode(body, "utf-8"), "(?P<ip>\\d+\\.\\d+\\.\\d+\\.\\d+).*(?P<user>\\w+)"))

Conditional Set

set(attributes["env"], "prod") where resource["k8s.namespace.name"] == "production"
set(attributes["env"], "dev") where attributes["env"] == nil

Mask Sensitive Data

set(cache["body"], Decode(body, "utf-8"))
replace_pattern(cache["body"], "\\b\\d{16}\\b", "****-****-****-****")
set(body, EDXEncode(cache["body"], "utf-8"))

Check Field Existence

set(attributes["has_user"], true) where attributes["user_id"] != nil
set(attributes["has_user"], false) where attributes["user_id"] == nil

Type-Safe Operations

set(attributes["count_int"], Int(attributes["count"])) where IsString(attributes["count"])
set(attributes["upper"], ConvertCase(attributes["name"], "upper")) where IsString(attributes["name"])

Multiple Conditions

set(attributes["alert"], true) where attributes["level"] == "error" and attributes["count"] > 10
set(attributes["skip"], true) where attributes["env"] == "test" or attributes["debug"] == true

Clean Up Fields

delete_matching_keys(attributes, "^debug_.*")
delete_matching_keys(attributes, "^internal_.*")
keep_keys(attributes, ["user_id", "request_id", "status", "duration"])

Time Format Patterns

PatternDescriptionExample
%Y4-digit year2025
%m2-digit month01
%d2-digit day02
%H2-digit hour (24h)15
%M2-digit minute30
%S2-digit second45
%fMicroseconds123456
%zTimezone offset+00:00

Common Formats:

  • ISO8601: %Y-%m-%dT%H:%M:%SZ
  • RFC3339: %Y-%m-%dT%H:%M:%S.%f%z
  • Apache: %d/%b/%Y:%H:%M:%S %z

Duration Units

UnitDescriptionExample
hHours"2h"
mMinutes"30m"
sSeconds"45s"
msMilliseconds"500ms"
usMicroseconds"1000us"
nsNanoseconds"1000000ns"

Combinations: "2h30m45s", "1h30m", "90s"

Regex Tips

Escape Special Characters

Double-escape backslashes in OTTL strings:

  • \\d for digit
  • \\s for whitespace
  • \\b for word boundary
  • \\. for literal dot

Named Capture Groups

Use (?P<name>pattern) for ExtractPatterns:

ExtractPatterns(str, "(?P<ip>\\d+\\.\\d+\\.\\d+\\.\\d+)")

Backreferences in Replacements

Use $$1, $$2 for capture group references:

replace_pattern(cache["str"], "(\\d{4})\\d{8}(\\d{4})", "$$1****$$2")

Common Mistakes

WrongCorrectIssue
ANDandUppercase operators fail
ORorUppercase operators fail
&&andC-style operators not supported
\d\\dNeed double-escape in strings
$1$$1Need double-dollar for backreference
body["field"]Decode(body, "utf-8")Body is bytes, not map

See Also