Skip to content
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 new delete functions #11824

Merged
merged 4 commits into from
Jul 11, 2022

Conversation

TylerHelmuth
Copy link
Member

Description:
Adds 2 new functions that allow deleting keys from maps.

Link to tracking Issue:
Closes #11823

Testing:
Added new unit tests and integration tests

Documentation:
Updated readme

@TylerHelmuth
Copy link
Member Author

/cc @anuraaga

@@ -33,6 +33,10 @@ Supported functions:
e.g., `set(attributes["http.path"], "/foo")`, `set(name, attributes["http.route"])`, `set(trace_state["svc"], "example")`, `set(attributes["source"], trace_state["source"])`. If `value` resolves to `nil`, e.g.
it references an unset map value, there will be no action.

- `delete_key(target, key)` - `target` is a path expression to a map type field. `key` is a string that is a key in the map. The key will be deleted from the map. e.g., `delete_key(attributes, "http.request.header.authorization")`

- `delete_matching_keys(target, pattern)` - `target` is a path expression to a map type field. `pattern` is a regex string. All keys that match the pattern will be deleted from the map. e.g., `delete_matching_keys(attributes, ".*\.header\.authorization")`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be delete_all_matches to be consistent with replace_all_matches?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but I didn't want anyone to think it deleted the matching sections in the map's value vs replacing it like replace_all_matches. I wanted it to be clear that its the whole entry being deleted, so I kept it closer to delete_key

@TylerHelmuth
Copy link
Member Author

@open-telemetry/collector-contrib-approvers please review

@TylerHelmuth
Copy link
Member Author

/cc @anuraaga

@anuraaga
Copy link
Contributor

anuraaga commented Jul 8, 2022

I think we added nil to the language recently. Is there a difference between set nil and delete?

@TylerHelmuth
Copy link
Member Author

TylerHelmuth commented Jul 8, 2022

I think we added nil to the language recently. Is there a difference between set nil and delete?

@anuraaga actually there is a defect with set and nil where set doesn't allow setting a value to nil because of the val != nil check. But if set did allow setting a values to nil, thenset(attribute["test"], nil) would keep that attribute key in the map and set its value to nil. The delete functions would completely remove the key and value from the map.

@TylerHelmuth
Copy link
Member Author

Opened #12193 for the set nil issue

@djaglowski djaglowski merged commit 43da034 into open-telemetry:main Jul 11, 2022
@TylerHelmuth TylerHelmuth deleted the issue-11823 branch July 11, 2022 15:59
atoulme pushed a commit to atoulme/opentelemetry-collector-contrib that referenced this pull request Jul 16, 2022
* Add new delete functions

* Updated changelog
ag-ramachandran referenced this pull request in ag-ramachandran/opentelemetry-collector-contrib Sep 15, 2022
* Add new delete functions

* Updated changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[processor/transform] Add ability to delete entries from a map.
4 participants