Skip to content

Commit 67bdff0

Browse files
authored
[processor/transform] Add examples for attribute rename (#21762)
* Add more examples * Update README.md * Update README.md
1 parent f8b65c1 commit 67bdff0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

processor/transformprocessor/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,39 @@ Set attribute `test` to `"pass"` if the attribute `test` does not exist:
258258
```yaml
259259
transform:
260260
error_mode: ignore
261-
span_statements:
261+
trace_statements:
262262
- context: span
263263
statements:
264264
# accessing a map with a key that does not exist will return nil.
265265
- set(attributes["test"], "pass") where attributes["test"] == nil
266266
```
267267

268+
### Rename attribute
269+
There are 2 ways to rename an attribute key:
270+
271+
You can either set a new attribute and delete the old:
272+
273+
```yaml
274+
transform:
275+
error_mode: ignore
276+
trace_statements:
277+
- context: resource
278+
statements:
279+
- set(attributes["namespace"], attributes["k8s.namespace.name"])
280+
- delete_key(attributes, "k8s.namespace.name")
281+
```
282+
283+
Or you can update the key using regex:
284+
285+
```yaml
286+
transform:
287+
error_mode: ignore
288+
trace_statements:
289+
- context: resource
290+
statements:
291+
- replace_all_patterns(attributes, "key", "k8s\\.namespace\\.name", "namespace")
292+
```
293+
268294
### Parsing JSON logs
269295

270296
Given the following json body

0 commit comments

Comments
 (0)