HasSuffix

Learn about the HasSuffix OTTL converter function.

The HasSuffix converter checks if a string ends with a specified suffix and returns a boolean value.

Syntax: HasSuffix(target, suffix)

  • target: the string to check
  • suffix: the suffix string to look for

Input

{
	"_type": "log",
	"body": {
		"suffix_test": "test_file.txt",
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

Statement

set(body["has_suffix_txt"], HasSuffix(body["suffix_test"], ".txt"))

Output

{
	"_type": "log",
	"body": {
		"suffix_test": "test_file.txt",
		"has_suffix_txt": true,
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

The function correctly identified that “test_file.txt” ends with “.txt”.