Transform Processor
contrib, k8s
Maintainers: @TylerHelmuth, @evan-bradley, @edmocosta, @bogdandrutu
Source: opentelemetry-collector-contrib
Supported Telemetry
Overview
The Transform Processor modifies telemetry based on configuration using the OpenTelemetry Transformation Language (OTTL). For each signal type, the processor takes a list of statements and executes them against the incoming telemetry, following the order specified in the configuration. Each statement can access and transform telemetry using functions, and allows the use of a condition to help decide whether the function should be executed.- Config
- Grammar
- Supported functions
- Examples
- Troubleshooting
- Contributing
- Feature Gate
- Compatibility
- Performance and scaling
- Self-observability
Config
General Config
[!NOTE] If you don’t know how to write OTTL statements yet, first see OTTL’s Getting Started docs.
- OTTL statements. This option will meet most user’s needs. See Basic Config for more details.
- Objects, which allows users to apply configuration options to a specific list of statements. See Advanced Config for more details.
[!NOTE] Support for theWithin eachprofilesignal (theprofile_statementsconfiguration and theprofilecontext) is experimental and subject to change or removal in the future.
<signal_statements> list, only certain OTTL Path prefixes can be used:
This means, for example, that you cannot use the Path
span.attributes within the log_statements configuration section.
error_mode: determines how the processor treats errors that occur while processing a statement.
If the top-level error_mode is not specified, ignore will be used.
The top-level error_mode can be overridden at statement group level, offering more granular control over error handling. If the statement group error_mode is not specified, the top-level error_mode is applied.
Basic Config
[!NOTE] If you don’t know how to write OTTL statements yet, first see OTTL’s Getting Started docs.The basic configuration style allows you to configure OTTL statements as a list, without worrying about extra configurations. This is the simplest way to configure the Transform Processor. If you need global conditions or specific error modes see Advanced Config. Format:
Advanced Config
[!NOTE] If you don’t know how to write OTTL statements yet, first see OTTL’s Getting Started docs.For more complex use cases you may need to use the Transform Processor’s advanced configuration style to group related OTTL statements. Format:
error_mode: allows overriding the top-level error_mode. See General Config for details on how to configure error_mode.
shared_cache (experimental): enables sharing per-context caches between all advanced statement groups with the option enabled in this Transform Processor instance. Use this when you want to hold state across multiple iterations over a set of data.
conditions: a list comprised of multiple where clauses, which will be processed as global conditions for the accompanying set of statements. The conditions are ORed together, which means only one condition needs to evaluate to true in order for the statements (including their individual Where clauses) to be executed.
statements: a list of OTTL statements.
Example:
statements are parsable.
In some situations a combination of Paths, functions, or enums is not allowed, and it might require multiple configuration groups.
See Context Inference for more details.
Context inference
[!NOTE] This is an advanced topic and is not necessary to get started using the Transform Processor. Read on if you’re interested in how the Transform Processor parses your OTTL statements.An OTTL Context defines which Paths, functions, and enums are available when parsing the statement. The Transform Processor automatically infers the OTTL Context based on the paths defined in a statement. This inference is based on the Path names, functions, and enums present in the statements. The inference happens automatically because Path names are prefixed with the Context name. For example:
datapoint, as it is the only Context
that supports parsing both datapoint and metric Paths.
In the following example, the inferred Context is metric,
as metric is the context capable of parsing both metric and resource data.
datapoint Path prefixed is used in the same group of statements as the convert_sum_to_gauge
function. Since convert_sum_to_gauge can only be used with the metrics, not datapoints, but the list
statements contains a reference to the datapoints via the datapoint Path prefix, the group of statements cannot
be parsed.
The solution is to separate the statements into separate Advanced Config groups:
Grammar
You can learn more in-depth details on the capabilities and limitations of the OpenTelemetry Transformation Language used by the Transform Processor by reading about its grammar.Supported functions:
These common functions can be used for any Signal. In addition to the common OTTL functions, the processor defines its own functions to help with transformations specific to this processor: Metrics only functions- convert_sum_to_gauge
- convert_gauge_to_sum
- extract_avg_metric
- extract_count_metric
- extract_percentile_metric
- extract_sum_metric
- convert_summary_count_val_to_sum
- convert_summary_quantile_val_to_gauge
- convert_summary_sum_val_to_sum
- copy_metric
- scale_metric
- aggregate_on_attributes
- convert_exponential_histogram_to_histogram
- aggregate_on_attribute_value
- merge_histogram_buckets
convert_sum_to_gauge
convert_sum_to_gauge()
Converts incoming metrics of type “Sum” to type “Gauge”, retaining the metric’s datapoints. Noop for metrics that are not of type “Sum”.
NOTE: This function may cause a metric to break semantics for Gauge metrics. Use at your own risk.
Examples:
convert_sum_to_gauge()
convert_gauge_to_sum
convert_gauge_to_sum(aggregation_temporality, is_monotonic)
Converts incoming metrics of type “Gauge” to type “Sum”, retaining the metric’s datapoints and setting its aggregation temporality and monotonicity accordingly. Noop for metrics that are not of type “Gauge”.
aggregation_temporality is a string ("cumulative" or "delta") that specifies the resultant metric’s aggregation temporality. is_monotonic is a boolean that specifies the resultant metric’s monotonicity.
NOTE: This function may cause a metric to break semantics for Sum metrics. Use at your own risk.
Examples:
-
convert_gauge_to_sum("cumulative", false) -
convert_gauge_to_sum("delta", true)
extract_avg_metric
[!NOTE]
This function supports Histograms, ExponentialHistograms and Summaries.
extract_avg_metric(Optional[suffix])
The extract_avg_metric function creates a new Gauge metric from a Histogram, ExponentialHistogram or Summary by dividing the sum value by the count value for each data point. Data points where the sum value is missing or the count value is 0 are skipped, to avoid division by zero. A metric will only be created if there is at least one data point.
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _avg.
The name for the new metric will be <original metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, description, and unit.
The new metric that is created will be passed to all subsequent statements in the metrics statements list.
Examples:
-
extract_avg_metric() -
extract_avg_metric(".avg")
extract_count_metric
[!NOTE]
This function supports Histograms, ExponentialHistograms and Summaries.
extract_count_metric(is_monotonic, Optional[suffix])
The extract_count_metric function creates a new Sum metric from a Histogram, ExponentialHistogram or Summary’s count value. A metric will only be created if there is at least one data point.
is_monotonic is a boolean representing the monotonicity of the new metric.
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _count.
The name for the new metric will be <original metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, description, and aggregation_temporality. As metrics of type Summary don’t have an aggregation_temporality field, this field will be set to AGGREGATION_TEMPORALITY_CUMULATIVE for those metrics.
The new metric that is created will be passed to all subsequent statements in the metrics statements list.
[!WARNING]Examples:
This function may cause a metric to break semantics for Sum metrics. Use only if you’re confident you know what the resulting monotonicity should be.
-
extract_count_metric(true, ".count") -
extract_count_metric(false, ".count")
extract_percentile_metric
[!NOTE]
This function supports Histograms and ExponentialHistograms.
extract_percentile_metric(percentile, Optional[suffix])
The extract_percentile_metric function creates a new Gauge metric from a Histogram or ExponentialHistogram by calculating the specified percentile value from the bucket counts. A metric will only be created if there is at least one data point.
percentile is a float64 value greater than 0 and less than 100 representing the desired percentile to extract (e.g., 50 for median, 95 for p95, 99 for p99).
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _p{percentile} (e.g., _p50, _p95, _p99).
The name for the new metric will be <original metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, description, and unit.
For Histograms, the function uses linear interpolation within buckets to estimate the percentile value. Since the lowest bucket has no finite lower bound (-Inf), the function uses the data point’s Min value when available. If Min is not set and the upper bound of that bucket is non-negative, the lower bound is assumed to be 0. Similarly, if the percentile falls in the last bucket (+Inf upper bound), the data point’s Max value is used for interpolation when available. For ExponentialHistograms, it uses logarithmic interpolation appropriate for the exponential bucket structure.
The new metric that is created will be passed to all subsequent statements in the metrics statements list.
Examples:
-
extract_percentile_metric(50.0)- Extract median (p50) with default suffix_p50 -
extract_percentile_metric(95.0, "_p95_custom")- Extract p95 with custom suffix_p95_custom -
extract_percentile_metric(99.9) where metric.name == "http.server.duration"- Extract p99.9 only for specific metrics
extract_sum_metric
[!NOTE]
This function supports Histograms, ExponentialHistograms and Summaries.
extract_sum_metric(is_monotonic, Optional[suffix])
The extract_sum_metric function creates a new Sum metric from a Histogram, ExponentialHistogram or Summary’s sum value. If the sum value of a Histogram or ExponentialHistogram data point is missing, no data point is added to the output metric. A metric will only be created if there is at least one data point.
is_monotonic is a boolean representing the monotonicity of the new metric.
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _sum.
The name for the new metric will be <original metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, description, and aggregation_temporality. As metrics of type Summary don’t have an aggregation_temporality field, this field will be set to AGGREGATION_TEMPORALITY_CUMULATIVE for those metrics.
The new metric that is created will be passed to all subsequent statements in the metrics statements list.
[!WARNING]Examples:
This function may cause a metric to break semantics for Sum metrics. Use only if you’re confident you know what the resulting monotonicity should be.
-
extract_sum_metric(true, ".sum") -
extract_sum_metric(false, ".sum")
convert_summary_count_val_to_sum
convert_summary_count_val_to_sum(aggregation_temporality, is_monotonic, Optional[suffix])
The convert_summary_count_val_to_sum function creates a new Sum metric from a Summary’s count value.
aggregation_temporality is a string ("cumulative" or "delta") representing the desired aggregation temporality of the new metric. is_monotonic is a boolean representing the monotonicity of the new metric.
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _count.
The name for the new metric will be <summary metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, and description. The new metric that is created will be passed to all functions in the metrics statements list. Function conditions will apply.
NOTE: This function may cause a metric to break semantics for Sum metrics. Use at your own risk.
Examples:
-
convert_summary_count_val_to_sum("delta", true, ".count") -
convert_summary_count_val_to_sum("cumulative", false, ".count")
convert_summary_quantile_val_to_gauge
convert_summary_quantile_val_to_gauge(Optional[attributeKey], Optional[suffix])
The convert_summary_quantile_val_to_gauge function creates a new Gauge metric and injects each of the Summary’s quantiles into a single Gauge datapoint.
attributeKey is an optional string that specifies the attribute key holding the quantile value for each corresponding output data point. The default key is quantile.
suffix is an optional string representing the suffix of the metric name. The default value is .quantiles.
The name for the new metric will be <summary metric name>.quantiles. The fields that are copied are: timestamp, starttimestamp, attributes, unit and description. The new metric that is created will be passed to all functions in the metrics statements list. Function conditions will apply.
Examples:
-
convert_summary_quantile_val_to_gauge("custom_quantile", "custom_suffix") -
convert_summary_quantile_val_to_gauge("custom_quantile") -
convert_summary_quantile_val_to_gauge()
convert_summary_sum_val_to_sum
convert_summary_sum_val_to_sum(aggregation_temporality, is_monotonic, Optional[suffix])
The convert_summary_sum_val_to_sum function creates a new Sum metric from a Summary’s sum value.
aggregation_temporality is a string ("cumulative" or "delta") representing the desired aggregation temporality of the new metric. is_monotonic is a boolean representing the monotonicity of the new metric.
suffix is an optional string that defines the suffix for the metric name. By default, it is set to _sum.
The name for the new metric will be <summary metric name><suffix>. The fields that are copied are: timestamp, starttimestamp, attributes, and description. The new metric that is created will be passed to all functions in the metrics statements list. Function conditions will apply.
NOTE: This function may cause a metric to break semantics for Sum metrics. Use at your own risk.
Examples:
-
convert_summary_sum_val_to_sum("delta", true, ".sum") -
convert_summary_sum_val_to_sum("cumulative", false, ".sum")
copy_metric
copy_metric(Optional[name], Optional[description], Optional[unit])
The copy_metric function copies the current metric, adding it to the end of the metric slice.
name is an optional string. description is an optional string. unit is an optional string.
The new metric will be exactly the same as the current metric. You can use the optional parameters to set the new metric’s name, description, and unit.
NOTE: The new metric is appended to the end of the metric slice and therefore will be included in all the metric statements. It is a best practice to ALWAYS include a Where clause when copying a metric that WILL NOT match the new metric.
Examples:
-
copy_metric(name="http.request.status_code", unit="s") where metric.name == "http.status_code -
copy_metric(desc="new desc") where metric.description == "old desc"
convert_exponential_histogram_to_histogram
Warning: This conversion is not defined by the OpenTelemetry Specification and may lose precision.convert_exponential_histogram_to_histogram(distribution, [ExplicitBounds])
Converts an exponential histogram to an explicit histogram.
The function requires two arguments:
distributioncontrols how each exponential bucket is allocated:upperplaces the bucket count at its upper bound.midpointplaces the bucket count at its arithmetic midpoint.uniformassumes a uniform distribution within the bucket and allocates counts according to the overlap with each explicit bucket. Rounding is deterministic.randomuses the same overlap calculation asuniform, with randomized rounding.
ExplicitBoundsis a non-empty, strictly increasing list of explicit histogram bounds.
- Converts positive, negative, and zero buckets.
- Preserves the total count.
- Contains
len(ExplicitBounds) + 1bucket counts. For bounds[b0, b1], the buckets are(-Inf, b0],(b0, b1], and(b1, +Inf).
scale_metric
scale_metric(factor, Optional[unit])
The scale_metric function multiplies the values in the data points in the metric by the float value factor.
If the optional string unit is provided, the metric’s unit will be set to this value.
The supported data types are:
Supported metric types are Gauge, Sum, Histogram, and Summary.
Examples:
scale_metric(0.1): Scale the metric by a factor of0.1. The unit of the metric will not be modified.scale_metric(10.0, "kWh"): Scale the metric by a factor of10.0and sets the unit tokWh.
aggregate_on_attributes
aggregate_on_attributes(function, Optional[attributes])
The aggregate_on_attributes function aggregates all data points in the metric.
function is a case-sensitive string that represents the aggregation function to apply. attributes is an optional list of datapoint attribute keys (strings) to aggregate upon.
The optional attributes argument controls which datapoint attributes are kept before aggregation:
- omitted (
aggregate_on_attributes(function)): all existing data point attributes are kept. Aggregation only combines data points that already share the same full attribute set. [](empty list): all datapoint attributes are removed. Aggregation is performed across all data points in the metric.[...](list of attribute keys): only the specified data point attributes are kept. All other attributes are removed, and aggregation is performed by grouping on the remaining attributes.
metric context.
The following metric types can be aggregated:
- sum
- gauge
- histogram
- exponential histogram
- sum
- max
- min
- mean
- median
- count
sum aggregation function is supported for histogram and exponential histogram datatypes.
Examples:
aggregate_on_attributes("sum", ["attr1", "attr2"]) where metric.name == "system.memory.usage"aggregate_on_attributes("max") where metric.name == "system.memory.usage"aggregate_on_attributes("max", []) where metric.name == "system.memory.usage"
aggregate_on_attributes function can also be used in conjunction with
keep_matching_keys or
delete_matching_keys.
For example, to remove attribute keys matching a regex and aggregate the metrics on the remaining attributes, you can perform the following statement sequence:
keep_matching_keys.
aggregate_on_attribute_value
aggregate_on_attribute_value(function, attribute, values, newValue)
The aggregate_on_attribute_value function aggregates all datapoints in the metric containing the attribute attribute (type string) with one of the values present in the values parameter (list of strings) into a single datapoint where the attribute has the value newValue (type string). function is a case-sensitive string that represents the aggregation function.
NOTE: This function is supported only in metric context.
The following metric types can be aggregated:
- sum
- gauge
- histogram
- exponential histogram
- sum
- max
- min
- mean
- median
- count
sum aggregation function is supported for histogram and exponential histogram datatypes.
Examples:
aggregate_on_attribute_value("sum", "attr1", ["val1", "val2"], "new_val") where metric.name == "system.memory.usage"
aggregate_on_attribute_value function can also be used in conjunction with
keep_matching_keys or
delete_matching_keys.
For example, to remove attribute keys matching a regex and aggregate the metrics on the remaining attributes, you can perform the following statement sequence:
keep_matching_keys.
merge_histogram_buckets
merge_histogram_buckets(target_value, method)
The merge_histogram_buckets function merges explicit histogram buckets. The method argument is optional and defaults to remove_explicit_bound.
target_value is interpreted according to method:
remove_explicit_bound:target_valueis the explicit boundary to remove. The function merges the bucket ending at this boundary with the next bucket. This method uses floating-point tolerance (epsilon = 1e-12) when matching the boundary.limit_buckets:target_valueis the maximum number of buckets to keep. It must be a positive integer. The function reduces resolution with a single uniform compaction pass. It chooses the smallest divisor that keeps the resulting bucket count at or belowtarget_value, merges adjacent buckets in groups of that size from lower to higher bucket order, combines their counts, and keeps any partial final group. Bucket count values and boundary widths do not affect which buckets are merged. The resulting histogram may have fewer thantarget_valuebuckets when no smaller uniform divisor can stay within the limit.
- Preserves the total count and sum of the histogram.
- Only works on histogram metrics (no-op for other metric types).
- Makes no changes if:
- The explicit boundary is not found when using
remove_explicit_bound. - The histogram is already at or below the requested bucket limit when using
limit_buckets. - The histogram is empty.
- The histogram structure is invalid (mismatched bounds and counts, or unordered bounds when using
limit_buckets).
- The explicit boundary is not found when using
limit_buckets method reduces histogram resolution and may affect percentile or quantile accuracy. Use only when you are confident that reducing bucket detail is acceptable for downstream consumers.
Examples:
ParseCEF
ParseCEF(target)
The ParseCEF function returns a pcommon.Map that is the result of parsing the target string as a Common Event Format (CEF) message.
target is a Getter that returns a string. If the returned string is empty, or cannot be parsed as CEF, an error will be returned.
ParseCEF is tolerant of an optional syslog header preceding the CEF: token; parsing begins at the first occurrence of CEF: in the input.
The returned map has the following top-level fields:
cef.version— the CEF version (the integer followingCEF:).cef.device_vendor,cef.device_product,cef.device_version,cef.device_event_class_id,cef.name,cef.severity— the six CEF header fields.cef.extensions— a map of the parsed key/value extension pairs.
\| (pipe) and \\ (backslash) are unescaped. Within extension values, the escape sequences \\ (backslash), \= (equals), \n (newline), and \r (carriage return) are unescaped.
Extension parsing uses the position of the next key= token as the end of the current value, so values may contain spaces. All extension values are returned as strings.
Examples:
-
ParseCEF(body) -
ParseCEF("CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232")
ParseCLF
ParseCLF(target, Optional[format])
The ParseCLF function returns a pcommon.Map that is the result of parsing the target string as a Common Log Format (CLF) HTTP access log entry.
target is a Getter that returns a string. If the returned string is empty, or cannot be parsed in the selected format, an error will be returned.
format is an optional string that selects the log format to parse. Valid values are:
-
"clf"(default) — the strict Common Log Format: -
"combined"— the NCSA Combined Log Format used by default in many Apache and nginx configurations, which is CLF with the quoted referer and user-agent appended:
request, referer, user-agent) may contain backslash escape sequences as produced by Apache (\", \\, \xhh, and C-style control escapes such as \n and \t — see the mod_log_config format notes) and nginx (\xhh). These sequences are unescaped in the returned values.
The returned map has the following fields:
clf.remote_host— the client’s DNS name or IP address.clf.rfc931— the remote logname of the user (CLF uses-when unknown).clf.auth_user— the authenticated user (CLF uses-when unknown).clf.timestamp— the contents of the bracketed date field, preserved as a string.clf.request— the raw request line as sent by the client.clf.method,clf.request_uri,clf.protocol— the parsed components of the request line, only set when the request line is well-formed.clf.status— the HTTP status code as an integer.clf.bytes— the content-length of the response as an integer. Omitted when CLF reports-(e.g. on a 304 response).clf.referer,clf.user_agent— the referer and user-agent strings, only set whenformatis"combined".
ParseCLF(body)ParseCLF("127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] \"GET /apache_pb.gif HTTP/1.0\" 200 2326")ParseCLF(body, "combined")
ParseELF
ParseELF(target)
The ParseELF function returns a pcommon.Map that is the result of parsing the target string as a W3C Extended Log Format (ELF) log block.
target is a Getter that returns a string containing a complete ELF log block (one or more directive lines followed by data lines). If the string is empty or does not contain a valid #Version directive, an error is returned.
Intended usage: ParseELF is designed for pipelines where the full ELF block — header directives (#Version, #Fields, etc.) and data lines — is available as a single string. This is the case when using the filelog receiver with a multiline configuration that groups an entire ELF file (or rotated segment) into one log record body, or when the entire log content is read from a single field. In a line-by-line streaming pipeline where #Fields arrives only once at file open, each individual data line does not carry its own header; for that pattern you would need to prepend the known header directives to each data line before passing the string to ParseELF.
The returned map contains the following keys:
elf.version— value of the#Versiondirective (required).elf.software— value of#Software(omitted if not present).elf.date— value of#Date(omitted if not present).elf.start_date— value of#Start-Date(omitted if not present).elf.end_date— value of#End-Date(omitted if not present).elf.remark— value of#Remark(omitted if not present).elf.fields— string slice of field names from the last#Fieldsdirective.elf.entries— slice of maps, one per data line, keyed by field name. Missing values are represented as"-".
#Fields directives within a single block are supported; each directive applies to subsequent data lines until the next #Fields directive is encountered. Double-quoted field values (as produced by Microsoft IIS) are handled correctly.
Examples:
-
ParseELF(body) -
ParseELF("#Version: 1.0\n#Fields: time cs-method cs-uri\n00:34:23 GET /foo/bar.html")
ParseLEEF
ParseLEEF(target)
The ParseLEEF function returns a pcommon.Map that is the result of parsing the target string as a Log Event Extended Format (LEEF) message.
target is a Getter that returns a string. If the returned string is empty, or cannot be parsed as LEEF, an error will be returned.
ParseLEEF can parse both LEEF 1.0 and LEEF 2.0 messages. The function is tolerant of an optional syslog header preceding the LEEF: token; parsing begins at the first occurrence of LEEF: in the input, so a literal LEEF: appearing in a syslog header ahead of the real header would be misinterpreted.
The returned map has the following top-level fields:
leef.version— the LEEF version ("1.0"or"2.0").leef.vendor,leef.product.name,leef.product.version,leef.event.id— the LEEF header fields.leef.attributes— a map of the parsed key/value attribute pairs.
0x-prefixed hex value decoding to a single byte (e.g. 0x09 for tab). An empty delimiter field defaults to tab. The delimiter field is also optional: if the position normally occupied by the delimiter looks like the start of an attribute (i.e. contains =), it is treated as the first attribute and the delimiter defaults to tab.
Attribute parsing is lenient: pairs without an = separator or with an empty key are silently skipped, and when the same key appears more than once the last occurrence wins. Whitespace within keys and values is preserved verbatim, since the LEEF spec defines a value as everything up to the delimiter.
All attribute values are returned as strings. LEEF defines a set of predefined event attributes (e.g. src, dst, srcPort, usrName, devTime) with expected types such as Integer, IPv4/IPv6, and Time.
Examples:
-
ParseLEEF(body) -
ParseLEEF("LEEF:1.0|Microsoft|MSExchange|4.0 SP1|15345|src=10.50.1.1\tdst=2.10.20.20\tsev=5") -
ParseLEEF("LEEF:2.0|Lancope|StealthWatch|1.0|41|^|src=10.0.1.8^dst=10.0.0.5^sev=5")
set_semconv_span_name
set_semconv_span_name(semconvVersion, Optional[originalSpanNameAttribute])
The set_semconv_span_name() function overwrites a span name using the OpenTelemetry semantic conventions for HTTP, RPC, messaging, and database spans. In other cases, the original span.name remains unchanged.
The primary use case of the set_semconv_span_name() function is to address high-cardinality issues in span metrics when span.name doesn’t comply with the OpenTelemetry requirement that span names be low cardinality such as GET /product/12345, GET/product?id=12345, or SELECT * FROM product WHERE id=12345.
Parameters:
semconvVersionis the version of the Semantic Conventions used to generate thespan.name. A set of older/deprecated semconv attributes are also supported for backward compatibility (see the table below). Versions1.37.0to1.43.0are supported.originalSpanNameAttributeis the optional name of the attribute used to copy the originalspan.nameif different from the name derived from semantic conventions.
- Span with high-cardinality name but recommended semantic convention attributes
- Incoming span:
- Span name after applying
set_semconv_span_name("1.43.0"):GET /api/v1/users/{id} - No loss of information on
span.nameoccurs because the recommended attributehttp.routeis present.
- Incoming span:
- Span with high-cardinality name lacking recommended semantic convention attribute
http.route- Incoming span:
- Span name after applying
set_semconv_span_name("1.43.0"):GET - Loss of information on
span.nameoccurs because the recommended attributehttp.routeis missing. Note that this loss of information is mitigated if the instrumentation produced attributes that contain the URL path likeurl.pathorurl.full.
- Incoming span:
- Compliant span name is unchanged
- Incoming span:
- Span name after applying
set_semconv_span_name("1.43.0"):GET /api/v1/users/{id}
- Incoming span:
set_semconv_span_name will also read the following deprecated attributes, mapping each to its current equivalent:
Examples:
-
set_semconv_span_name("1.43.0") -
set_semconv_span_name("1.43.0", "original_span_name")
Examples
Perform transformation if field does not exist
Set attributetest to "pass" if the attribute test does not exist:
Rename attribute
There are 2 ways to rename an attribute key: You can either set a new attribute and delete the old:Move field to attribute
Set attributebody to the value of the log body:
Combine two attributes
Set attributetest to the value of attributes "foo" and "bar" combined.
Parsing JSON logs
Given the following json bodyOverride context statements error mode
Get Severity of an Unstructured Log Body
Given the following unstructured log bodyCopy attributes matching regular expression to a separate location
If you want to move resource attributes, which keys are matching the regular expressionpod_labels_.* to a new attribute
location kubernetes.labels, use the following configuration:
delete_matching_keys() to copy the attributes that do not match the regular expression.
Troubleshooting
When using OTTL you can enable debug logging in the collector to print out useful information, such as the current Statement and the current TransformContext, to help you troubleshoot why a statement is not behaving as you expect. This feature is very verbose, but provides you an accurate view into how OTTL views the underlying data.Contributing
See CONTRIBUTING.md.Warnings
The Transform Processor uses the OpenTelemetry Transformation Language (OTTL) which allows users to modify all aspects of their telemetry. Some specific risks are listed below, but this is not an exhaustive list. In general, understand your data before using the Transform Processor.- Unsound Transformations: Several Metric-only functions allow you to transform one metric data type to another or create new metrics from an existing metrics. Transformations between metric data types are not defined in the metrics data model. These functions have the expectation that you understand the incoming data and know that it can be meaningfully converted to a new metric data type or can meaningfully be used to create new metrics.
- Although the OTTL allows the
setfunction to be used withmetric.data_type, its implementation in the Transform Processor is NOOP. To modify a data type you must use a function specific to that purpose.
- Although the OTTL allows the
- Identity Conflict: Transformation of metrics have the potential to affect the identity of a metric leading to an Identity Crisis. Be especially cautious when transforming metric name and when reducing/changing existing attributes. Adding new attributes is safe.
- Orphaned Telemetry: The processor allows you to modify
span_id,trace_id, andparent_span_idfor traces andspan_id, andtrace_idlogs. Modifying these fields could lead to orphaned spans or logs. - Other: Statements that modify a higher context (
resourceorscope) using values from a lower context (for example,set(resource.attributes["to"], log.attributes["from"])) may produce unexpected results. The statement runs once per span, metric, or log record, and every record that shares the same resource or scope writes to the same shared value, so the last record processed determines the final value. For logs, theflatten_dataoption can be used to avoid this. See #32080 for more details.
Feature Gate
transform.flatten.logs
The transform.flatten.logs feature gate enables the flatten_data configuration option (default false). With flatten_data: true, the processor provides each log record with a distinct copy of its resource and scope. Then, after applying all transformations, the log records are regrouped by resource and scope.
This option is useful when applying transformations which alter the resource or scope. e.g. set(resource.attributes["to"], log.attributes["from"]), which may otherwise result in unexpected behavior. Using this option typically incurs a performance penalty as the processor must compute many hashes and create copies of resource and scope information for every log record.
The feature is currently only available for log processing.
Example Usage
config.yaml:
./otelcol --config config.yaml --feature-gates=transform.flatten.logs
ottl.set.allowNil
The ottl.set.allowNil feature gate changes the behavior of the OTTL set function when a nil value is evaluated. When enabled, set will pass the nil value directly to the target. Depending on the target, this may result in an error or an empty value. See the OTTL Documentation for full details and migration instructions.
Compatibility
The Transform Processor operates only on the telemetry flowing through the pipeline and has no external service or system dependencies. Its behavior is defined entirely by the OTTL functions, paths, and enums it exposes, which are versioned together with the processor in each OpenTelemetry Collector release. There are no external dependency versions to track for compatibility. Configuration syntax and OTTL semantics follow the OpenTelemetry Collector’s versioning and stability policies. Breaking changes to configuration or OTTL behavior are gated behind feature gates and announced in the changelog.Performance and scaling
The Transform Processor is stateless across batches: each incoming batch is processed independently, so the processor requires no coordination and can be scaled horizontally by running additional Collector replicas. Theshared_cache option and OTTL’s cache only hold state for the duration of
a single execution and are never shared across batches or replicas.
CPU and memory cost scale with the number and complexity of the statements you configure and with the
volume of telemetry flowing through the pipeline. To keep the processor efficient:
- Use conditions (statement-level
whereclauses or advanced global conditions) to skip statements for telemetry they don’t apply to. - Prefer fewer, more targeted statements over broad transformations applied to all telemetry.
- The
flatten_dataoption incurs a performance penalty because the processor must compute hashes and copy resource and scope information for every log record.
Self-observability
The Transform Processor does not emit any component-specific metrics or spans. It relies on the standard telemetry that the Collector produces for every processor, which is described in the Collector’s internal telemetry documentation.Metrics
The following metrics are emitted for the processor:otelcol_processor_incoming_items: the number of items (spans, metric data points, or log records) passed to the processor.otelcol_processor_outgoing_items: the number of items emitted by the processor.otelcol_processor_internal_duration: a histogram of the time taken to process a batch of telemetry through the processor.
otel.signal and processor attributes, so you can observe throughput per
signal and per configured transform processor instance.
Logs
The amount of detail the processor logs is controlled by the Collector’sservice::telemetry::logs::level
setting:
- At
info(the default), the processor logs no per-statement information. Errors are logged according to the configurederror_mode:ignorelogs each failed statement or condition atwarnlevel,silentsuppresses them entirely, andpropagatereturns the error up the pipeline (where the payload is dropped and the failure is surfaced by the pipeline rather than by the processor). - At
debug, OTTL additionally logs the details it uses to evaluate your statements: the OTTL context it infers for each statement group, theTransformContextbefore a statement sequence runs and after every individual statement executes, and the result of each condition evaluation. This is very verbose but is the most useful level for debugging why a statement is or isn’t behaving as expected, since it shows exactly how OTTL sees the underlying data. See Troubleshooting for an example of this output.
Configuration
Example Configuration
Last generated: 2026-10-05