Concat

Learn about the Concat OTTL converter function.

Overview

The Concat converter concatenates multiple fields with a specified delimiter.

Syntax

Concat(values, delimiter)

  • values: array of fields to concatenate
  • delimiter: a string separator between concatenated values

Examples

Input

{
	"_type": "log",
	"body": "12:34 [INFO] hello info - i am an info log - username:foobar, password=fancycat",
	"resource": {
		"ed.conf.id": "123456789",
		"ed.domain": "pipeline",
		"ed.org.id": "987654321",
		"ed.source.name": "__ed_dummy_test_input",
		"ed.source.type": "memory_input",
		"ed.tag": "loggen",
		"host.ip": "10.0.0.1",
		"host.name": "ED_TEST",
		"k8s.namespace": "my-namespace",
		"k8s.pod.name": "my-pod",
		"service.name": "ed-tester",
		"src_type": "memory_input"
	},
	"timestamp": 1733443632205
}

Statement

set(resource["pod_full_name"], Concat([resource["k8s.pod.name"], resource["k8s.namespace"]], "."))

Output

{
	"_type": "log",
	"body": "12:34 [INFO] hello info - i am an info log - username:foobar, password=fancycat",
	"resource": {
		"ed.conf.id": "123456789",
		"ed.domain": "pipeline",
		"ed.org.id": "987654321",
		"ed.source.name": "__ed_dummy_test_input",
		"ed.source.type": "memory_input",
		"ed.tag": "loggen",
		"host.ip": "10.0.0.1",
		"host.name": "ED_TEST",
		"k8s.namespace": "my-namespace",
		"k8s.pod.name": "my-pod",
		"pod_full_name": "my-pod.my-namespace",
		"service.name": "ed-tester",
		"src_type": "memory_input"
	},
	"timestamp": 1733443608806
}

The pod name and namespace were concatenated with a . to create a unique pod_full_name.

Dynamic arguments

The delimiter argument can be read from a field instead of a literal string.

Input

{
	"_type": "log",
	"body": {
		"prefix_field": "ERROR",
		"status": "active",
		"concat_sep": "-"
	},
	"resource": {...},
	"attributes": {}
}

Statement

set(attributes["concat_dynamic"], Concat([body["prefix_field"], body["status"]], body["concat_sep"]))

Output

{
	"_type": "log",
	"body": {
		"prefix_field": "ERROR",
		"status": "active",
		"concat_sep": "-"
	},
	"resource": {...},
	"attributes": {
		"concat_dynamic": "ERROR-active"
	}
}

The separator - was read from body["concat_sep"] and used to join the two fields.