TrimSuffix

Remove a specified suffix from the end of a string using the TrimSuffix OTTL converter function.

Overview

The TrimSuffix converter removes a specified suffix from the end of a string. If the string does not end with the suffix, it is returned unchanged.

Syntax

TrimSuffix(target, suffix)

  • target: the string to trim
  • suffix: the suffix string to remove

Examples

Input

{
	"_type": "log",
	"body": {
		"filename": "report_2026_final.csv"
	},
	"resource": {...},
	"attributes": {}
}

Statement

set(attributes["trimmed_name"], TrimSuffix(body["filename"], ".csv"))
set(attributes["no_match"], TrimSuffix(body["filename"], ".pdf"))

Output

{
	"_type": "log",
	"body": {
		"filename": "report_2026_final.csv"
	},
	"resource": {...},
	"attributes": {
		"trimmed_name": "report_2026_final",
		"no_match": "report_2026_final.csv"
	}
}

The .csv suffix was removed from the filename. When the suffix does not match (.pdf), the original string is returned unchanged.