-
Couldn't load subscription status.
- Fork 586
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.