IsRootSpan

Learn about the IsRootSpan OTTL converter function.

The IsRootSpan converter checks if a span is a root span (has no parent) and returns a boolean value. This is useful for identifying the entry point of a distributed trace.

Syntax: IsRootSpan()

Note: This function operates on the span context and only works with trace telemetry data.

Input

{
	"_type": "span",
	"traceID": "7bba9f33312b3dbb8b2c2c62bb7abe2d",
	"spanID": "086e83747d0e381e",
	"parentSpanID": "",
	"name": "HTTP GET /api/users",
	"attributes": {...}
}

Statement

set(attributes["is_root"], IsRootSpan())

Output

{
	"_type": "span",
	"traceID": "7bba9f33312b3dbb8b2c2c62bb7abe2d",
	"spanID": "086e83747d0e381e",
	"parentSpanID": "",
	"name": "HTTP GET /api/users",
	"attributes": {
		"is_root": true
	}
}

The function identified this span as a root span because it has no parent span ID.