Keys

Learn about the Keys OTTL converter function.

The Keys converter extracts all keys from a map and returns them as a list.

Syntax: Keys(map)

  • map: the map field to extract keys from

Input

{
	"_type": "log",
	"body": "User session data",
	"resource": {...},
	"attributes": {
		"session_data": {
			"user_id": "12345",
			"login_time": "2024-01-10T10:00:00Z",
			"ip_address": "192.168.1.100",
			"browser": "Chrome",
			"os": "Windows"
		}
	}
}

Statement

set(attributes["session_keys"], Keys(attributes["session_data"]))

Output

{
	"_type": "log",
	"body": "User session data",
	"resource": {...},
	"attributes": {
		"session_data": {
			"user_id": "12345",
			"login_time": "2024-01-10T10:00:00Z",
			"ip_address": "192.168.1.100",
			"browser": "Chrome",
			"os": "Windows"
		},
		"session_keys": ["user_id", "login_time", "ip_address", "browser", "os"]
	}
}

The Keys function extracted all key names from the session_data map.