Skip to content

Conversation

@leghadjeu-christian
Copy link
Contributor

@leghadjeu-christian leghadjeu-christian commented Oct 14, 2025

Fixes #3163

Changes

Adds a new get_ref method to opentelemetry_sdk::Resource that returns a reference to the stored value instead of cloning it. This improves performance and avoids unnecessary allocations for read-only access, while keeping the existing get method for backward compatibility.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@leghadjeu-christian leghadjeu-christian requested a review from a team as a code owner October 14, 2025 16:15
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 14, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: leghadjeu-christian / name: leghadjeu.christian (e5d29d9, ef45ca7)

@codecov
Copy link

codecov bot commented Oct 14, 2025

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.6%. Comparing base (c75413c) to head (ef45ca7).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
opentelemetry-sdk/src/resource/mod.rs 0.0% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3198     +/-   ##
=======================================
- Coverage   80.7%   80.6%   -0.1%     
=======================================
  Files        128     128             
  Lines      23195   23198      +3     
=======================================
  Hits       18719   18719             
- Misses      4476    4479      +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@scottgerring scottgerring left a comment

Choose a reason for hiding this comment

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

Hey @leghadjeu-christian thanks for raising this! Looks like a straightforward performance improvement with minimal side effects to me.

There's not really an established pattern of .get and .get_ref in the SDKs API, but I see no cleaner option to do this without a breaking change, which as you've pointed out we don't want.

The one other thing I note is that here:

.get(&Key::from_static_str("service.name"))

... could also be changed to use .as_ref !

Copy link
Member

@scottgerring scottgerring left a comment

Choose a reason for hiding this comment

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

Thanks - LGTM!

processor
.resource()
.get(&Key::from_static_str(resource_key))
.get_ref(&Key::from_static_str(resource_key))
Copy link
Member

Choose a reason for hiding this comment

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

I have requested for some additional information on the need of this new method here.

Irrespective of that, I am fine adding the new method. One comment - unless really needed, let's keep all existing usage unmodified in this PR. If needed, I'd prefer to have a follow up PR updating all usages to the new method. This helps keep PRs short and easy to see that this is purely additive change.

Copy link
Member

@cijothomas cijothomas left a comment

Choose a reason for hiding this comment

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

The change is good. I suggest to not modify test code. etc to use the new method in this PR.

@cijothomas cijothomas merged commit c4f59da into open-telemetry:main Nov 6, 2025
26 of 27 checks passed
@leghadjeu-christian leghadjeu-christian deleted the feature/resource-get-ref branch November 6, 2025 16:45
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.

Resource::get always cloning the returned Value

3 participants