HasPrefix

Learn about the HasPrefix OTTL converter function.

The HasPrefix converter checks if a string starts with a specified prefix and returns a boolean value.

Syntax: HasPrefix(target, prefix)

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

Input

{
	"_type": "log",
	"body": {
		"prefix_test": "hello_world",
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

Statement

set(body["has_prefix_hello"], HasPrefix(body["prefix_test"], "hello"))

Output

{
	"_type": "log",
	"body": {
		"prefix_test": "hello_world",
		"has_prefix_hello": true,
		"run": 23
	},
	"resource": {...},
	"timestamp": 1727750400000
}

The function correctly identified that “hello_world” starts with “hello”.