transform processor with signal-specific *_statements and, when needed, conditions to selectively modify telemetry.
Key takeaway: the transform processor only affects telemetry for the pipeline it is attached to (traces, metrics, or logs). Make sure you wire it into the correct pipeline.
When you change the transform configuration, restart the collector and the apps sending telemetry so you can observe the effects.
Quick recap: trace transformations
A typical transform configuration that updates resource attributes, spans, and span events looks like this:Logs
We’ll generate logs using a smalllog.py script that prints logs at different severities. Before you add transforms, inspect the raw records using the collector’s debug exporter.
Example transform configuration that updates log attributes, severity, and body:
context: logoperates on the LogRecord.- Use
attributes[...]to add/modify log attributes. - Overwrite
severity_textto change severity label (e.g.,INFO,ERROR). - Overwrite
bodyto replace the log message. - Without
conditions, statements apply to every log record.
Additional log contexts
The transform processor supports other contexts for logs besideslog, such as resource and scope. These allow you to modify resource-level attributes and instrumentation scope metadata.
Example:
Metrics
Metrics usemetric_statements and support contexts like metric, datapoint, and resource. You can modify metric descriptors (name, description, unit), and operate on individual datapoints.
Example: change a metric descriptor only when the metric name matches current_temperature_fahrenheit:
current_temperature_fahrenheit will be transformed and appear as new.metric.name with updated descriptor fields:
Data point context
Usecontext: datapoint to modify individual datapoints — add datapoint attributes, override timestamps, or change values.
Example:
Deleting or keeping keys (attribute filtering)
You can delete specific attribute keys or keep only a whitelist. The same APIs exist for traces, logs, and metrics — below examples use trace/span context. Delete a key:bank attribute from spans where the statement executes. To run only when that key exists, add a condition such as attributes["bank"] != nil.
Keep only a whitelist of keys:
keep_keys(attributes, [...]) removes all other keys from the attributes map except those specified.
Example debug output after keeping only username and account_number:
keep_keys(attributes, ["username", "account_number"]), other keys such as some-key would be removed.
Transform contexts quick reference
| Context type | Signals supported | What you can modify | Example statement |
|---|---|---|---|
resource | traces, logs, metrics | Resource attributes | set(attributes["platform"], "kubernetes") |
span / spanevent | traces | Span attributes, events | set(attributes["some-key"], "some-value") |
log | logs | LogRecord attributes, body, severity_text | set(body, "new body") |
scope | logs, traces | Instrumentation scope name/attributes | set(name, "my.scope.name") |
metric | metrics | Metric descriptor (name, description, unit) | set(name, "new.metric.name") |
datapoint | metrics | Datapoint attributes, timestamps, values | set(value_int, 100) |
Final checklist and best practices
- Add the transform processor to the correct pipeline(s): traces, metrics, and/or logs.
- Confirm your YAML structure: each
contextblock must includestatements:and, optionally,conditions:(as a list). - Use valid OTTL expressions inside
conditions:, for example:attributes["bank"] != nilname == "current_temperature_fahrenheit"
- When iterating on rules, use the collector debug exporter and restart both the collector and telemetry-generating processes so changes take effect.
- Test incrementally: apply simple transformations first (e.g., set a single attribute), verify output, then expand to more complex rules.
Use the debug exporter in the collector to inspect the transformed telemetry while you iterate on OTTL rules.
Links and references
- OpenTelemetry Collector Transform Processor
- OTTL (OpenTelemetry Transformation Language) Reference
- Kubernetes Documentation