-
Notifications
You must be signed in to change notification settings - Fork 703
Apply validation of attributes to Resource
, move attribute related logic to util package
#1834
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e08e586
Update Resource attributes to comply with Attributes specification
srikanthccv 4d72201
Fix tests
srikanthccv b7aafd5
Fix lint
srikanthccv 10f35c7
Fix invalid byte type
srikanthccv 1be3c17
Bug fix
srikanthccv aee5f90
Remove unused import
srikanthccv 8b915cf
Fix lint; Add CHANGELOG entry
srikanthccv 5c8b9a1
Merge branch 'main' into issue-1831
srikanthccv 178d635
Fix lint
srikanthccv 8f76e2c
Update CHANGELOG.md
srikanthccv 276b339
Update CHANGELOG entry
srikanthccv 9ab68fa
Merge branch 'main' into issue-1831
srikanthccv 0137d12
Resolve merge conflicts
srikanthccv ba65385
Address review comments
srikanthccv 5a30d10
Add License
srikanthccv 0a36c67
fix lint
srikanthccv b3a4a44
Merge branch 'main' into issue-1831
b4d09db
Make methods private
srikanthccv f9b2bc1
Merge branch 'issue-1831' of github.com:lonewolf3739/opentelemetry-py…
srikanthccv 026dda1
Merge branch 'main' into issue-1831
srikanthccv 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
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 |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
) | ||
from opentelemetry.sdk.trace import Resource, sampling | ||
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator | ||
from opentelemetry.sdk.util import ns_to_iso_str | ||
from opentelemetry.sdk.util import _is_valid_attribute_value, ns_to_iso_str | ||
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo | ||
from opentelemetry.trace import StatusCode | ||
from opentelemetry.util._time import _time_ns | ||
|
@@ -647,32 +647,26 @@ def test_byte_type_attribute_value(self): | |
|
||
def test_check_attribute_helper(self): | ||
# pylint: disable=protected-access | ||
self.assertFalse(trace._is_valid_attribute_value([1, 2, 3.4, "ss", 4])) | ||
self.assertFalse( | ||
trace._is_valid_attribute_value([dict(), 1, 2, 3.4, 4]) | ||
) | ||
self.assertFalse( | ||
trace._is_valid_attribute_value(["sw", "lf", 3.4, "ss"]) | ||
) | ||
self.assertFalse(trace._is_valid_attribute_value([1, 2, 3.4, 5])) | ||
self.assertTrue(trace._is_valid_attribute_value([1, 2, 3, 5])) | ||
self.assertTrue(trace._is_valid_attribute_value([1.2, 2.3, 3.4, 4.5])) | ||
self.assertTrue(trace._is_valid_attribute_value([True, False])) | ||
self.assertTrue(trace._is_valid_attribute_value(["ss", "dw", "fw"])) | ||
self.assertTrue(trace._is_valid_attribute_value([])) | ||
self.assertFalse(trace._is_valid_attribute_value(dict())) | ||
self.assertTrue(trace._is_valid_attribute_value(True)) | ||
self.assertTrue(trace._is_valid_attribute_value("hi")) | ||
self.assertTrue(trace._is_valid_attribute_value(3.4)) | ||
self.assertTrue(trace._is_valid_attribute_value(15)) | ||
self.assertFalse(_is_valid_attribute_value([1, 2, 3.4, "ss", 4])) | ||
self.assertFalse(_is_valid_attribute_value([dict(), 1, 2, 3.4, 4])) | ||
self.assertFalse(_is_valid_attribute_value(["sw", "lf", 3.4, "ss"])) | ||
self.assertFalse(_is_valid_attribute_value([1, 2, 3.4, 5])) | ||
self.assertTrue(_is_valid_attribute_value([1, 2, 3, 5])) | ||
self.assertTrue(_is_valid_attribute_value([1.2, 2.3, 3.4, 4.5])) | ||
self.assertTrue(_is_valid_attribute_value([True, False])) | ||
self.assertTrue(_is_valid_attribute_value(["ss", "dw", "fw"])) | ||
self.assertTrue(_is_valid_attribute_value([])) | ||
self.assertFalse(_is_valid_attribute_value(dict())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: please group all the true/false together. makes it easier to read :) |
||
self.assertTrue(_is_valid_attribute_value(True)) | ||
self.assertTrue(_is_valid_attribute_value("hi")) | ||
self.assertTrue(_is_valid_attribute_value(3.4)) | ||
self.assertTrue(_is_valid_attribute_value(15)) | ||
# None in sequences are valid | ||
self.assertTrue(trace._is_valid_attribute_value(["A", None, None])) | ||
self.assertTrue( | ||
trace._is_valid_attribute_value(["A", None, None, "B"]) | ||
) | ||
self.assertTrue(trace._is_valid_attribute_value([None, None])) | ||
self.assertFalse(trace._is_valid_attribute_value(["A", None, 1])) | ||
self.assertFalse(trace._is_valid_attribute_value([None, "A", None, 1])) | ||
self.assertTrue(_is_valid_attribute_value(["A", None, None])) | ||
self.assertTrue(_is_valid_attribute_value(["A", None, None, "B"])) | ||
self.assertTrue(_is_valid_attribute_value([None, None])) | ||
self.assertFalse(_is_valid_attribute_value(["A", None, 1])) | ||
self.assertFalse(_is_valid_attribute_value([None, "A", None, 1])) | ||
|
||
def test_sampling_attributes(self): | ||
sampling_attributes = { | ||
|
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.
Should all of this logic go into the api?
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.
Maybe if we want to provide this as part of public api package
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 guess other SDKs could use a method like this to ensure their attributes are all validated and users could potentially use this to validate/filter their attributes before setting them? not sure how likely these scenarios are though. I could go either ways with 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.
I was more referring to the fact that
Attribute
s are an API concept. I don't think they need to be part of the PUBLIC api, simply private methods that exist in the api package.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.
Are
Attributes
s an API concept? I am inclined towards keeping them in sdk because all operations are no-op in api package so we will probably never use them there and if we don't want offer them as a part of public api to user/application owners I don't see any benefit in moving to api package?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.
Yes
Attribute
s are defined in the API. Hmm now thinking about it, this is probably valuable and common enough to be exposed in the public api. It is also defined in the specs so I don't mind increasing our api surface for this. For example, this would be useful for instrumentations to leverage (which only have dependencies on the api).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 can move this to api util package. I just want to make sure we are okay with making these public because of all of util is pretty much private and internal.
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.
You can be the first :)