-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[processor/transform] Add replace_match and replace_all_matches functions #10132
[processor/transform] Add replace_match and replace_all_matches functions #10132
Conversation
@dehaansa your review is my new favorite lol all typos should be fixed |
/cc @anuraaga. I opted to rename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looking forward to this function
@@ -31,6 +31,10 @@ the fields specified by the list of strings. e.g., `keep_keys(attributes, "http. | |||
|
|||
- `limit(target, limit)` - `target` is a path expression to a map type field. `limit` is 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 limit `attributes` to no more than 100 items. Which items are dropped is random. | |||
|
|||
- `replace_match(target, pattern, replacement)` - `target` is a path expression to a telemetry field, `pattern` is a string following [filepath.Match syntax](https://pkg.go.dev/path/filepath#Match), and `replacement` is a string. If `target` matches `pattern` it will get replaced with `replacement`. e.g., `replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}")` | |||
|
|||
- `replace_all_matches(target, pattern, replacement)` - `target` is a path expression to a map type field, `pattern` is a string following [filepath.Match syntax](https://pkg.go.dev/path/filepath#Match), and `replacement` is a string. Each string value in `target` that matches `pattern` will get replaced with `replacement`. e.g., `replace_all_matches(attributes, "/user/*/list/*", "/user/{userId}/list/{listId}")` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there is a significant use case for this, it's rare for many attributes to match the same string I guess. If just two or so which seems imaginable, two replace_match seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not a significant number of use cases, but I like the flexibility. Also a good example of function syntax standards.
@open-telemetry/collector-contrib-approvers please review. |
@open-telemetry/collector-contrib-maintainer please review. I'd like to get this in for the 0.52.0 release. |
…ions (open-telemetry#10132) * add replace_match and repalce_all_matches functions
Description:
This PR adds 2 new functions,
replace_match
andreplace_all_matches
.replace_match
takes a telemetry path and replace's it with the supplied replacement if the value matches the supplied pattern.replace_all_matches
does the same, exact on all possible values on a supplied map.Link to tracking Issue:
Related to #8252
Testing:
Added unit tests
Documentation:
Updated README. Submitted PR to update processing.md doc