-
Notifications
You must be signed in to change notification settings - Fork 572
Open
Labels
A-commonArea:common issues that not related to specific pillarArea:common issues that not related to specific pillar
Description
Issue
I noticed the the opentelemetry_sdk::Resource::get(&self, &Key) -> Value
needs to returned an owned Value
, and thus always clones it.
The operation is not that expensive when the underlying value is a number, of a static/Arc String. But it does require and allocation for reading values that are owned string, and array values.
This is a bit annoying for instance:
- when writing span processors that need to check the presence of a field on the Resource frequently without storing them.
- when writing span exporters that just need a reference to the data for serialization
Proposal
I think a more flexible API would be to return a reference and modify the signature to Resource::get(&self, &Key) -> &Value
.
Although this is a breaking change, existing users of that API would just do get(key).cloned()
instead if they really need to have a owned value.
Another option if we don't want to break the API is to keep the old get
as before and add a get_ref
method.
cijothomas
Metadata
Metadata
Assignees
Labels
A-commonArea:common issues that not related to specific pillarArea:common issues that not related to specific pillar