-
Notifications
You must be signed in to change notification settings - Fork 500
[SDK] custom hash and equality for attribute processor #3643
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
Changes from 7 commits
faccac5
844f1a2
7a05e7f
f199a59
a38b2d7
121bfcf
53012d2
0a81688
98543fc
63b2338
e5ad0c9
662b23f
a0a5540
ae5eeb9
4991c29
3e8f5c7
5c5c3cc
49e8152
7320c35
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,6 +3,7 @@ | |||||||||
|
||||||||||
#pragma once | ||||||||||
|
||||||||||
#include <cstring> | ||||||||||
#include <string> | ||||||||||
#include <unordered_map> | ||||||||||
#include <utility> | ||||||||||
|
@@ -18,8 +19,91 @@ namespace sdk | |||||||||
{ | ||||||||||
namespace metrics | ||||||||||
{ | ||||||||||
|
||||||||||
using MetricAttributes = opentelemetry::sdk::metrics::FilteredOrderedAttributeMap; | ||||||||||
|
||||||||||
/** | ||||||||||
* Hash and equality for nostd::string_view, enabling safe use in unordered_map | ||||||||||
* without requiring null termination. | ||||||||||
*/ | ||||||||||
struct StringViewHash | ||||||||||
{ | ||||||||||
#if __cplusplus >= 202002L | ||||||||||
// enable heterogenous lookup in C++20+ | ||||||||||
using is_transparent = void; | ||||||||||
#endif | ||||||||||
|
||||||||||
std::size_t operator()(const std::string &s) const noexcept | ||||||||||
{ | ||||||||||
return std::hash<std::string>{}(s); | ||||||||||
} | ||||||||||
|
||||||||||
std::size_t operator()(opentelemetry::nostd::string_view sv) const noexcept | ||||||||||
{ | ||||||||||
#if __cplusplus >= 202002L | ||||||||||
return std::hash<opentelemetry::nostd::string_view>{}( | ||||||||||
opentelemetry::nostd::string_view{sv.data(), sv.size()}); | ||||||||||
|
return std::hash<opentelemetry::nostd::string_view>{}( | |
opentelemetry::nostd::string_view{sv.data(), sv.size()}); | |
// Materialize to std::string to ensure safe hashing (string_view may not be null-terminated) | |
return std::hash<std::string>{}(std::string{sv.data(), sv.size()}); |
Copilot uses AI. Check for mistakes.
Uh oh!
There was an error while loading. Please reload this page.