Skip to content

Commit c4f59da

Browse files
leghadjeu-christianscottgerringcijothomas
authored
feat: add get_ref to retrieve Resource values by reference (#3198)
Co-authored-by: Scott Gerring <scottgerring@users.noreply.github.com> Co-authored-by: Cijo Thomas <cijo.thomas@gmail.com>
1 parent c75413c commit c4f59da

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

opentelemetry-sdk/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## vNext
44

5+
### Added
6+
- Added `Resource::get_ref(&self, key: &Key) -> Option<&Value>` to allow retrieving a reference to a resource value without cloning.
7+
58
## 0.31.0
69

710
Released 2025-Sep-25

opentelemetry-sdk/src/resource/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ impl Resource {
228228
pub fn get(&self, key: &Key) -> Option<Value> {
229229
self.inner.attrs.get(key).cloned()
230230
}
231+
232+
/// Returns a reference to the value for the resource associated with the given key without cloning.
233+
pub fn get_ref(&self, key: &Key) -> Option<&Value> {
234+
self.inner.attrs.get(key)
235+
}
231236
}
232237

233238
/// An iterator over the entries of a `Resource`.

0 commit comments

Comments
 (0)