-
Notifications
You must be signed in to change notification settings - Fork 542
Add bundle version of utf8_range to validate attributes #3512
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
owent
wants to merge
41
commits into
open-telemetry:main
Choose a base branch
from
owent:validate_utf8_string_in_setters
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
41 commits
Select commit
Hold shift + click to select a range
622f8fb
Add bundle version of utf8_range to validate attribute values
owent b529903
Fixes styles and copyright
owent c924a76
Fixes type in `utf8_range_IsTrailByteOk`
owent d89343c
Fixes IWYU and clang-tidy warnings
owent d800b20
Add unit tests for resources and trace span
owent 823fbfb
Add CHANGELOG
owent 1702bc5
Fixes warnings
owent d0b4bfe
Fixes a ununsed warning
owent 3c70972
Merge branch 'main' into validate_utf8_string_in_setters
owent 1f75948
Merge branch 'main' into validate_utf8_string_in_setters
owent 0de8b28
Merge branch 'main' into validate_utf8_string_in_setters
lalitb 4c552f4
Merge branch 'main' into validate_utf8_string_in_setters
owent 339c7b6
Fixes cppcheck warning
owent 2ab31e8
Merge branch 'main' into validate_utf8_string_in_setters
ThomsonTan cd524a3
Merge branch 'main' into validate_utf8_string_in_setters
owent 1fd6ef7
Merge branch 'main' into validate_utf8_string_in_setters
owent ff58708
Fixes inline
owent 6625f78
Merge branch 'main' into validate_utf8_string_in_setters
owent 52ef536
Merge branch 'main' into validate_utf8_string_in_setters
owent dbaa91d
Merge branch 'main' into validate_utf8_string_in_setters
owent 007b26a
Merge branch 'main' into validate_utf8_string_in_setters
owent 83cb1d3
Fixes markdownlint
owent c9323e9
Merge remote-tracking branch 'github/main' into validate_utf8_string_…
owent e1af872
Bump github/codeql-action from 4.30.9 to 4.31.0 (#3720)
dependabot[bot] 29324be
Bump actions/download-artifact from 5.0.0 to 6.0.0 (#3719)
dependabot[bot] 1f0fb58
[CONFIGURATION] File configuration - prometheus translation (#3715)
marcalff 9caafe6
[SDK] Misc cleanup in attribute_utils.h (#3716)
Reneg973 86ca715
[TEST] Disable test BasicCurlHttpTests.SendGetRequestAsync (#3722)
marcalff 879121e
[SDK] Add cardinality_limit to all derived classes of AggregationConf…
ThomsonTan c94aab5
Bump github/codeql-action from 4.31.0 to 4.31.2 (#3733)
dependabot[bot] 33c9782
[BUILD] Upgrade to opentelemetry-proto 1.8.0 (#3730)
marcalff 615311e
[SEMANTIC CONVENTIONS] Upgrade to semantic conventions 1.38.0 (#3729)
marcalff 8766117
[CONFIGURATION] Implement declarative configuration (config.yaml) (#2…
marcalff 08e80f3
Show diff when shelltest failed
owent 3eabe75
Merge remote-tracking branch 'opentelemetry/main' into validate_utf8_…
owent 0136fb1
Fixes attribute order changes in kitchen-sink.test
owent ea1820b
Merge branch 'main' into validate_utf8_string_in_setters
owent 893fc56
Merge branch 'main' into validate_utf8_string_in_setters
owent 0ea4710
Merge remote-tracking branch 'opentelemetry/main' into validate_utf8_…
owent a96d252
Fixes clang-tidy
owent 49b474a
Merge branch 'main' into validate_utf8_string_in_setters
lalitb 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
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
152 changes: 152 additions & 0 deletions
152
sdk/include/opentelemetry/sdk/common/attribute_validity.h
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,152 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "opentelemetry/common/attribute_value.h" | ||
| #include "opentelemetry/common/key_value_iterable.h" | ||
| #include "opentelemetry/nostd/function_ref.h" | ||
| #include "opentelemetry/nostd/span.h" | ||
| #include "opentelemetry/nostd/string_view.h" | ||
| #include "opentelemetry/sdk/common/attribute_utils.h" | ||
| #include "opentelemetry/version.h" | ||
|
|
||
| OPENTELEMETRY_BEGIN_NAMESPACE | ||
| namespace sdk | ||
| { | ||
| namespace common | ||
| { | ||
|
|
||
| OPENTELEMETRY_EXPORT bool AttributeIsValidString(nostd::string_view value) noexcept; | ||
|
|
||
| /** | ||
| * Validate if an attribute value is valid. | ||
| */ | ||
| struct AttributeValidator | ||
| { | ||
| bool operator()(bool /*v*/) noexcept { return true; } | ||
| bool operator()(int32_t /*v*/) noexcept { return true; } | ||
| bool operator()(uint32_t /*v*/) noexcept { return true; } | ||
| bool operator()(int64_t /*v*/) noexcept { return true; } | ||
| bool operator()(uint64_t /*v*/) noexcept { return true; } | ||
| bool operator()(double /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::string_view v) noexcept { return AttributeIsValidString(v); } | ||
| bool operator()(const std::string &v) noexcept { return AttributeIsValidString(v); } | ||
| bool operator()(const char *v) noexcept { return AttributeIsValidString(v); } | ||
| bool operator()(nostd::span<const uint8_t> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const bool> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const int32_t> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const uint32_t> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const int64_t> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const uint64_t> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const double> /*v*/) noexcept { return true; } | ||
| bool operator()(nostd::span<const nostd::string_view> v) noexcept | ||
| { | ||
| for (const auto &s : v) | ||
| { | ||
| if (!AttributeIsValidString(s)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| bool operator()(const std::vector<bool> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<int32_t> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<uint32_t> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<int64_t> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<double> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<std::string> &v) | ||
| { | ||
| for (const auto &s : v) | ||
| { | ||
| if (!AttributeIsValidString(s)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| return true; | ||
| } | ||
| bool operator()(const std::vector<uint64_t> & /*v*/) noexcept { return true; } | ||
| bool operator()(const std::vector<uint8_t> & /*v*/) noexcept { return true; } | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsValid(const std::string &value) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsValid(nostd::string_view value) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsValid(const OwnedAttributeValue &value) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsValid( | ||
| const opentelemetry::common::AttributeValue &value) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsAllValid(const AttributeMap &attributes) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static bool IsAllValid(const OrderedAttributeMap &attributes) noexcept; | ||
|
|
||
| OPENTELEMETRY_EXPORT static void Filter(AttributeMap &attributes, nostd::string_view log_hint); | ||
|
|
||
| OPENTELEMETRY_EXPORT static void Filter(OrderedAttributeMap &attributes, | ||
| nostd::string_view log_hint); | ||
| }; | ||
|
|
||
| /** | ||
| * Supports internal iteration over a collection of key-value pairs and filtering of invalid | ||
| * attributes. | ||
| */ | ||
| class OPENTELEMETRY_EXPORT KeyValueFilterIterable : public opentelemetry::common::KeyValueIterable | ||
| { | ||
| public: | ||
| KeyValueFilterIterable(const opentelemetry::common::KeyValueIterable &origin, | ||
| opentelemetry::nostd::string_view log_hint) noexcept; | ||
|
|
||
| ~KeyValueFilterIterable() override; | ||
|
|
||
| KeyValueFilterIterable(const KeyValueFilterIterable &other) = default; | ||
| KeyValueFilterIterable &operator=(const KeyValueFilterIterable &other) = default; | ||
| KeyValueFilterIterable(KeyValueFilterIterable &&other) noexcept | ||
| : origin_(other.origin_), size_(other.size_), log_hint_(other.log_hint_) | ||
| { | ||
| other.origin_ = nullptr; | ||
| other.size_ = 0; | ||
| } | ||
|
|
||
| KeyValueFilterIterable &operator=(KeyValueFilterIterable &&other) noexcept | ||
| { | ||
| if (this != &other) | ||
| { | ||
| origin_ = other.origin_; | ||
| size_ = other.size_; | ||
| log_hint_ = other.log_hint_; | ||
|
|
||
| other.origin_ = nullptr; | ||
| other.size_ = 0; | ||
| } | ||
| return *this; | ||
| } | ||
|
|
||
| bool ForEachKeyValue( | ||
| opentelemetry::nostd::function_ref<bool(opentelemetry::nostd::string_view, | ||
| opentelemetry::common::AttributeValue)> callback) | ||
| const noexcept override; | ||
|
|
||
| size_t size() const noexcept override; | ||
|
|
||
| private: | ||
| // Pointer to the original KeyValueIterable | ||
| const opentelemetry::common::KeyValueIterable *origin_; | ||
|
|
||
| // Size of valid attributes | ||
| mutable size_t size_; | ||
|
|
||
| // Log hint for invalid attributes | ||
| opentelemetry::nostd::string_view log_hint_; | ||
| }; | ||
|
|
||
| } // namespace common | ||
| } // 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
Oops, something went wrong.
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.
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.
If we have to place invalid utf8 sequences into byte attribute values per the spec should the IsValid check always be performed when constructing an attribute map (attribute_utils.h)?
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, it looks like the spec changed after the initial version of this PR.
In the earlier version, bytes were allowed in log attributes, but not in traces, metrics, or resources.
I’ll review the spec again over the next few days and update the implementation to match the latest version.
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.
Looking at the spec it may only apply utf8 validation to OTLP type mapping. If that is the case we may be able to make a more isolated change to
OtlpPopulateAttributeUtils::PopulateAnyValueto support this as @lalitb suggests.