-
Notifications
You must be signed in to change notification settings - Fork 440
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
[SDK] Fix include instrumentation scope attributes in equal method #3214
[SDK] Fix include instrumentation scope attributes in equal method #3214
Conversation
✅ Deploy Preview for opentelemetry-cpp-api-docs canceled.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3214 +/- ##
==========================================
+ Coverage 87.82% 88.16% +0.35%
==========================================
Files 195 198 +3
Lines 6154 6224 +70
==========================================
+ Hits 5404 5487 +83
+ Misses 750 737 -13
|
Co-authored-by: Marc Alff <[email protected]>
Co-authored-by: Marc Alff <[email protected]>
CI has passed. Ready for review. |
const opentelemetry::common::AttributeValue &value) noexcept { | ||
// Perform a linear search to find the key assuming the map is small | ||
// This avoids temporary string creation from this->find(std::string(key)) | ||
for (const auto &kv : *this) |
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.
Do you think we can use this->find(kv.first)
here for better performance?
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.
It seems we have to start the search from the KeyValueIterable::ForEachKeyValue
method and it provides a nostd::string_view
key while the key type of the map is std::string
. So we either have to iterate directly like this or create a temp string every time as in auto iter = this->find(std::string(key))
. I chose the first option since it I've heard it could be faster than find for small maps :) and I didn't feel like string allocation (and its potential to throw) was ideal. I could profile both options if it seems worth it.
C++20 gives the "Heterogeneous comparison lookup" version of the std::unordered_map::find
method of unordered_map which is really what we need here. Here's a neat example https://godbolt.org/z/Yqsx4rsY1
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 for the details. Looks ok to me as is.
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.
LGTM, thanks for the fix.
Very well done, and with good test coverage.
…tation_scope_attributes_in_equal_method
I realized i missed a comment and update to operator== of the InstrumentationScope. Will push a commit shortly. |
…erator to check attributes. add a test and minor fixes/comments to the tests
Done. CI passed. |
Fixes #3208
Changes
This PR updates the GetTracer, GetMeter, and GetLogger methods to include instrumentation scope attributes in the equality check before returning a cached instance.
For significant contributions please make sure you have completed the following items:
CHANGELOG.md
updated for non-trivial changes