Skip to content

Conversation

leghadjeu-christian
Copy link

@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
Copy link

linux-foundation-easycla bot commented Oct 14, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

codecov bot commented Oct 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.8%. Comparing base (3b2f751) to head (b21e15b).

Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3198   +/-   ##
=====================================
  Coverage   80.8%   80.8%           
=====================================
  Files        128     128           
  Lines      23090   23096    +6     
=====================================
+ Hits       18676   18682    +6     
  Misses      4414    4414           

☔ 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!

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

2 participants