-
Notifications
You must be signed in to change notification settings - Fork 628
[SDK] Add Entity support to Resource #4490
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
Open
shashankxrm
wants to merge
21
commits into
open-telemetry:main
Choose a base branch
from
shashankxrm:fix/resource-entity-3652
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
838a3e7
[RESOURCE] Add Entity value type
shashankxrm be6372e
[RESOURCE] Add Entity storage to Resource
shashankxrm 8d25553
[RESOURCE] Add Entity support to Resource
shashankxrm f49b062
[RESOURCE] Add entity-aware Merge and Create support
shashankxrm e167baf
Add Entity support entry to CHANGELOG
shashankxrm fa79664
Update CHANGELOG.md to remove empty space under the update
shashankxrm 3bac7cc
Update CMakeLists.txt for linespace adjustment
shashankxrm 8a7792e
Update resource.cc to make insertion function more efficient
shashankxrm 44e4f4d
Update resource.cc emplace function
shashankxrm 6696d2f
[RESOURCE] Fix CI formatting and static analysis issues
shashankxrm 1e9bc31
Update resource_test.cc for placement change of include statement
shashankxrm 7a749a2
[RESOURCE] Fix clang-tidy copy warnings
shashankxrm 90a9b09
Merge branch 'main' into fix/resource-entity-3652
dbarker 8fbcaab
Fix Entity constructor and special members
shashankxrm 721fd24
Document Resource merge algorithms
shashankxrm 8bc70ef
Fix Resource merge ordering for entity schema
shashankxrm 87e3d11
Merge branch 'main' into fix/resource-entity-3652
ThomsonTan 7a0f12b
Optimize attribute-only Resource storage
shashankxrm 40438ca
Merge branch 'main' into fix/resource-entity-3652
ThomsonTan f4bf097
Normalize integer Entity identities
shashankxrm 4f26c21
Include what you use fix
shashankxrm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "opentelemetry/sdk/common/attribute_utils.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace resource | ||
| { | ||
|
|
||
| using ResourceAttributes = opentelemetry::sdk::common::AttributeMap; | ||
|
|
||
| class Entity | ||
| { | ||
| public: | ||
| /** | ||
| * Constructs an Entity. Integer identity values (and integer arrays) are | ||
| * canonicalized to int64_t when they fit, so C++ integer widths do not | ||
| * affect identity equality or merge. Description values are not rewritten. | ||
| */ | ||
| Entity(const std::string &type, | ||
| const ResourceAttributes &identity, | ||
| const ResourceAttributes &description = ResourceAttributes{}, | ||
| const std::string &schema_url = std::string{}); | ||
|
|
||
| const std::string &GetType() const noexcept; | ||
| const ResourceAttributes &GetIdentity() const noexcept; | ||
| const ResourceAttributes &GetDescription() const noexcept; | ||
| const std::string &GetSchemaURL() const noexcept; | ||
|
|
||
| bool IsValid() const noexcept; | ||
|
|
||
| bool operator==(const Entity &other) const noexcept; | ||
|
|
||
| private: | ||
| std::string type_; | ||
| ResourceAttributes identity_; | ||
| ResourceAttributes description_; | ||
| std::string schema_url_; | ||
| }; | ||
|
|
||
| } // namespace resource | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include "opentelemetry/sdk/resource/entity.h" | ||
|
|
||
| #include <cstdint> | ||
| #include <limits> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "opentelemetry/nostd/variant.h" | ||
| #include "opentelemetry/sdk/common/attribute_utils.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace resource | ||
| { | ||
| namespace | ||
| { | ||
|
|
||
| namespace nostd = opentelemetry::nostd; | ||
| using OwnedAttributeValue = opentelemetry::sdk::common::OwnedAttributeValue; | ||
|
|
||
| bool Uint64FitsInt64(std::uint64_t value) noexcept | ||
| { | ||
| return value <= static_cast<std::uint64_t>(std::numeric_limits<std::int64_t>::max()); | ||
| } | ||
|
|
||
| template <typename T> | ||
| OwnedAttributeValue WidenIntegerArray(const std::vector<T> &src) | ||
| { | ||
| std::vector<std::int64_t> dst; | ||
| dst.reserve(src.size()); | ||
| for (T value : src) | ||
| { | ||
| dst.push_back(static_cast<std::int64_t>(value)); | ||
| } | ||
| return OwnedAttributeValue{std::move(dst)}; | ||
| } | ||
|
|
||
| OwnedAttributeValue NormalizeIntegerIdentityValue(const OwnedAttributeValue &value) | ||
| { | ||
| if (nostd::holds_alternative<std::int32_t>(value)) | ||
| { | ||
| return OwnedAttributeValue{static_cast<std::int64_t>(nostd::get<std::int32_t>(value))}; | ||
| } | ||
| if (nostd::holds_alternative<std::uint32_t>(value)) | ||
| { | ||
| return OwnedAttributeValue{static_cast<std::int64_t>(nostd::get<std::uint32_t>(value))}; | ||
| } | ||
| if (nostd::holds_alternative<std::uint64_t>(value)) | ||
| { | ||
| const std::uint64_t raw = nostd::get<std::uint64_t>(value); | ||
| if (Uint64FitsInt64(raw)) | ||
| { | ||
| return OwnedAttributeValue{static_cast<std::int64_t>(raw)}; | ||
| } | ||
| return value; | ||
| } | ||
| if (nostd::holds_alternative<std::vector<std::int32_t>>(value)) | ||
| { | ||
| return WidenIntegerArray(nostd::get<std::vector<std::int32_t>>(value)); | ||
| } | ||
| if (nostd::holds_alternative<std::vector<std::uint32_t>>(value)) | ||
| { | ||
| return WidenIntegerArray(nostd::get<std::vector<std::uint32_t>>(value)); | ||
| } | ||
| if (nostd::holds_alternative<std::vector<std::uint64_t>>(value)) | ||
| { | ||
| const auto &src = nostd::get<std::vector<std::uint64_t>>(value); | ||
| for (std::uint64_t element : src) | ||
| { | ||
| if (!Uint64FitsInt64(element)) | ||
| { | ||
| return value; | ||
| } | ||
| } | ||
| return WidenIntegerArray(src); | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| void NormalizeIdentityIntegers(ResourceAttributes &identity) | ||
| { | ||
| for (auto &kv : identity) | ||
| { | ||
| kv.second = NormalizeIntegerIdentityValue(kv.second); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| Entity::Entity(const std::string &type, | ||
| const ResourceAttributes &identity, | ||
| const ResourceAttributes &description, | ||
| const std::string &schema_url) | ||
| : type_(type), identity_(identity), description_(description), schema_url_(schema_url) | ||
| { | ||
| NormalizeIdentityIntegers(identity_); | ||
| for (const auto &kv : identity_) | ||
| { | ||
| description_.erase(kv.first); | ||
| } | ||
| } | ||
|
|
||
| const std::string &Entity::GetType() const noexcept | ||
| { | ||
| return type_; | ||
| } | ||
|
|
||
| const ResourceAttributes &Entity::GetIdentity() const noexcept | ||
| { | ||
| return identity_; | ||
| } | ||
|
|
||
| const ResourceAttributes &Entity::GetDescription() const noexcept | ||
| { | ||
| return description_; | ||
| } | ||
|
|
||
| const std::string &Entity::GetSchemaURL() const noexcept | ||
| { | ||
| return schema_url_; | ||
| } | ||
|
|
||
| bool Entity::IsValid() const noexcept | ||
| { | ||
| return !type_.empty() && !identity_.empty(); | ||
| } | ||
|
|
||
| bool Entity::operator==(const Entity &other) const noexcept | ||
| { | ||
| return type_ == other.type_ && identity_ == other.identity_ && | ||
| description_ == other.description_ && schema_url_ == other.schema_url_; | ||
| } | ||
|
|
||
| } // namespace resource | ||
| } // namespace sdk | ||
| OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.