| Status |  | 
| Stability | alpha | 
| Supported pipeline types | traces, metrics, logs | 
| Distributions | contrib | 
The transform processor modifies telemetry based on configuration using the Telemetry Query Language.
It takes a list of queries which are performed in the order specified in the config.
Queries are composed of the following parts
- Path expressions: Fields within the incoming data can be referenced using expressions composed of the names as defined
in the OTLP protobuf definition. e.g., status.code,attributes["http.method"]. If the path expression begins withresource.orinstrumentation_library., it will reference those values.  For metrics,name,description,unit,type,is_monotonic, andaggregation_temporalityare accessed viametric.
- The name instrumentation_librarywithin OpenTelemetry is currently under discussion and may be changed in the future.
- Metric data types are None,Gauge,Sum,Histogram,ExponentialHistogram, andSummary
- aggregation_temporalityis converted to and from the protobuf's numeric definition.  Interact with this field using 0, 1, or 2.
- Until the grammar can handle booleans, is_monoticis handled via strings the strings"true"and"false".
 
- Literals: Strings, ints, and floats can be referenced as literal values
- Function invocations: Functions can be invoked with arguments matching the function's expected arguments
- Where clause: Telemetry to modify can be filtered by appending where a <op> b, withaandbbeing any of the above.
Supported functions:
- 
set(target, value)-targetis a path expression to a telemetry field to setvalueinto.valueis any value type.
e.g.,set(attributes["http.path"], "/foo"),set(name, attributes["http.route"]). Ifvalueresolves tonil, e.g.
it references an unset map value, there will be no action.
 
- 
keep_keys(target, string...)-targetis a path expression to a map type field. The map will be mutated to only contain
the fields specified by the list of strings. e.g.,keep_keys(attributes, "http.method"),keep_keys(attributes, "http.method", "http.route")
 
- 
truncate_all(target, limit)-targetis a path expression to a map type field.limitis a non-negative integer.  The map will be mutated such that all string values are truncated to the limit. e.g.,truncate_all(attributes, 100)will truncate all string values inattributessuch that all string values have less than or equal to 100 characters.  Non-string values are ignored.
 
- 
limit(target, limit)-targetis a path expression to a map type field.limitis a non-negative integer.  The map will be mutated such that the number of items does not exceed the limit. e.g.,limit(attributes, 100)will limitattributesto no more than 100 items. Which items are dropped is random.
 
- 
replace_match(target, pattern, replacement)-targetis a path expression to a telemetry field,patternis a string following filepath.Match syntax, andreplacementis a string. Iftargetmatchespatternit will get replaced withreplacement. e.g.,replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}")
 
- 
replace_all_matches(target, pattern, replacement)-targetis a path expression to a map type field,patternis a string following filepath.Match syntax, andreplacementis a string. Each string value intargetthat matchespatternwill get replaced withreplacement. e.g.,replace_all_matches(attributes, "/user/*/list/*", "/user/{userId}/list/{listId}")
 
Metric only functions:
- 
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.
 
- 
convert_gauge_to_sum(aggregation_temporality, is_monotonic)-aggregation_temporalityspecifies the resultant metric's aggregation temporality.aggregation_temporalitymay be"cumulative"or"delta".is_monotonicspecifies the resultant metric's monotonicity.is_monotonicis a boolean. 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".
NOTE: This function may cause a metric to break semantics for Sum metrics. Use at your own risk.
 
Supported where operations:
- ==- matches telemetry where the values are equal to each other
- !=- matches telemetry where the values are not equal to each other
Example configuration:
receivers:
  otlp:
    protocols:
      grpc:
exporters:
  nop
processors:
  transform:
    traces:
      queries:
        - set(status.code, 1) where attributes["http.path"] == "/health"
        - keep_keys(resource.attributes, "service.name", "service.namespace", "cloud.region")
        - set(name, attributes["http.route"])
        - replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}")
        - limit(attributes, 100)
        - limit(resource.attributes, 100)
        - truncate_all(attributes, 4096)
        - truncate_all(resource.attributes, 4096)
    metrics:
      queries:
        - set(metric.description, "Sum") where metric.type == "Sum"
        - keep_keys(resource.attributes, "host.name")
        - limit(attributes, 100)
        - truncate_all(attributes, 4096)
        - truncate_all(resource.attributes, 4096)
        - convert_sum_to_gauge() where metric.name == "system.processes.count"
        - convert_gauge_to_sum("cumulative", false) where metric.name == "prometheus_metric"
    logs:
      queries:
        - set(severity_text, "FAIL") where body == "request failed"
        - replace_all_matches(attributes, "/user/*/list/*", "/user/{userId}/list/{listId}")
        - set(body, attributes["http.route"])
        - keep_keys(resource.attributes, "service.name", "service.namespace", "cloud.region")
service:
  pipelines:
    logs:
      receivers: [otlp]
      processors: [transform]
      exporters: [nop]
    traces:
      receivers: [otlp]
      processors: [transform]
      exporters: [nop]
This processor will perform the operations in order for
All spans
- Set status code to OK for all spans with a path /health
- Keep only service.name,service.namespace,cloud.regionresource attributes
- Set nameto thehttp.routeattribute if it is set
- Replace the value of an attribute named http.targetwith/user/{userId}/list/{listId}if the value matched/user/*/list/*
- Limit all span attributes such that each span has no more than 100 attributes.
- Limit all resource attributes such that each resource no more than 100 attributes.
- Truncate all span attributes such that no string value has more than 4096 characters.
- Truncate all resource attributes such that no string value has more than 4096 characters.
All metrics and their data points
- Set metric description to "Sum" if the metric type is "Sum"
- Keep only the host.nameresource attributes
- Limit all data point attributes such that each data point has no more than 100 attributes.
- Truncate all data point attributes such that no string value has more than 4096 characters.
- Truncate all resource attributes such that no string value has more than 4096 characters.
- Convert all metrics with name system.processes.countfrom a Sum to Gauge.
- Convert all metrics with name prometheus_metricfrom Gauge to a cumulative, non-monotonic Sum.
All logs
- Set severity text to FAIL if the body contains a string text "request failed"
- Replace any attribute value that matches /user/*/list/*with/user/{userId}/list/{listId}
- Set bodyto thehttp.routeattribute if it is set
- Keep only service.name,service.namespace,cloud.regionresource attributes