-
Notifications
You must be signed in to change notification settings - Fork 590
feat: add get_ref to retrieve Resource values by reference #3198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add get_ref to retrieve Resource values by reference #3198
Conversation
…nnecessary cloning
…nnecessary cloning
…eu-christian/opentelemetry-rust into feature/resource-get-ref
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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:
opentelemetry-rust/stress/src/logs.rs
Line 71 in 3b2f751
| .get(&Key::from_static_str("service.name")) |
... could also be changed to use .as_ref !
Co-authored-by: Scott Gerring <scottgerring@users.noreply.github.com>
…eu-christian/opentelemetry-rust into feature/resource-get-ref
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Fixes #3163
Changes
Adds a new
get_refmethod toopentelemetry_sdk::Resourcethat 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 existinggetmethod for backward compatibility.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial, user-facing changes