Improve attributes validation#460
Merged
toumorokoshi merged 3 commits intoopen-telemetry:masterfrom Mar 10, 2020
Merged
Conversation
4fca8c9 ("Add runtime validation in setAttribute (open-telemetry#348)") added a robust attribute validation using numbers.Number to validate numeric types. Although the approach is correct, it presents some complications because Complex, Fraction and Decimal are accepted because they are Numbers. This presents a problem to the exporters because they will have to consider all these different cases when converting attributes to the underlying exporter representation. This commit simplifies the logic by accepting only int and float as numeric values.
c24t
approved these changes
Mar 9, 2020
| if first_element_type not in (bool, str, int, float): | ||
| return "invalid type" | ||
|
|
||
| # int and float are both numeric types, allow mixed arrays of those |
Member
There was a problem hiding this comment.
This and Sequence[Union[int, float]] above: do we really want to allow mixed-type array attributes?
Member
Author
There was a problem hiding this comment.
Good point. #348 added a specific test for that. The specification is not that clear, it talks about numeric as a primitive type [1]. Having a second thought, float and int are treated different in the exporters, so I think it would make sense not to avoid mixed arrays of those. If you agree I could update this.
Member
There was a problem hiding this comment.
I don't want this to block the PR, up to you whether to update this in this PR or another one.
Member
Author
There was a problem hiding this comment.
I updated the PR to avoid that kind of mixed attributes.
Member
|
Nice, thanks! |
toumorokoshi
added a commit
to toumorokoshi/opentelemetry-python
that referenced
this pull request
Mar 16, 2020
Total Changelog: Documentations has been significantly overhauled, including: * a getting started guide * examples has been consolidated to an docs/examples folder * several minor improvements to the examples in each extension's readme. - Adding Correlation Context API and propagator ([open-telemetry#471](open-telemetry#471)) - Adding a global configuration module to simplify setting and getting globals ([open-telemetry#466](open-telemetry#466)) - Rename metric handle to bound metric ([open-telemetry#470](open-telemetry#470)) - Moving resources to sdk ([open-telemetry#464](open-telemetry#464)) - Implementing propagators to API to use context ([open-telemetry#446](open-telemetry#446)) - Implement observer instrument for metrics ([open-telemetry#425](open-telemetry#425)) - Adding named meters, removing batchers ([open-telemetry#431](open-telemetry#431)) - Renaming TraceOptions to TraceFlags ([open-telemetry#450](open-telemetry#450)) - Renaming TracerSource to TraceProvider ([open-telemetry#441](open-telemetry#441)) - Adding Correlation Context SDK and propagator ([open-telemetry#471](open-telemetry#471)) - Adding OT Collector metrics exporter ([open-telemetry#454](open-telemetry#454)) - Improve validation of attributes ([open-telemetry#460](open-telemetry#460)) - Re-raise errors caught in opentelemetry.sdk.trace.Tracer.use_span() (open-telemetry#469) ([open-telemetry#469](open-telemetry#469)) - Adding named meters, removing batchers ([open-telemetry#431](open-telemetry#431)) - Make counter and MinMaxSumCount aggregators thread safe ([open-telemetry#439](open-telemetry#439)) - Initial release. Support is included for both trace and metrics.
c24t
pushed a commit
to c24t/opentelemetry-python
that referenced
this pull request
Mar 16, 2020
Total Changelog: Documentations has been significantly overhauled, including: * a getting started guide * examples has been consolidated to an docs/examples folder * several minor improvements to the examples in each extension's readme. - Adding Correlation Context API and propagator ([open-telemetry#471](open-telemetry#471)) - Adding a global configuration module to simplify setting and getting globals ([open-telemetry#466](open-telemetry#466)) - Rename metric handle to bound metric ([open-telemetry#470](open-telemetry#470)) - Moving resources to sdk ([open-telemetry#464](open-telemetry#464)) - Implementing propagators to API to use context ([open-telemetry#446](open-telemetry#446)) - Implement observer instrument for metrics ([open-telemetry#425](open-telemetry#425)) - Adding named meters, removing batchers ([open-telemetry#431](open-telemetry#431)) - Renaming TraceOptions to TraceFlags ([open-telemetry#450](open-telemetry#450)) - Renaming TracerSource to TraceProvider ([open-telemetry#441](open-telemetry#441)) - Adding Correlation Context SDK and propagator ([open-telemetry#471](open-telemetry#471)) - Adding OT Collector metrics exporter ([open-telemetry#454](open-telemetry#454)) - Improve validation of attributes ([open-telemetry#460](open-telemetry#460)) - Re-raise errors caught in opentelemetry.sdk.trace.Tracer.use_span() (open-telemetry#469) ([open-telemetry#469](open-telemetry#469)) - Adding named meters, removing batchers ([open-telemetry#431](open-telemetry#431)) - Make counter and MinMaxSumCount aggregators thread safe ([open-telemetry#439](open-telemetry#439)) - Initial release. Support is included for both trace and metrics.
srikanthccv
pushed a commit
to srikanthccv/opentelemetry-python
that referenced
this pull request
Nov 1, 2020
* chore: move members list out of community repo * chore: minor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
#348 added some runtime checks for attributes values, however I think this could create some issues to the exporter because it's accepting types as fractions, decimal and complex. This PR changes the logic to only accept int and float, otherwise exporter will have to handle all those different datatypes, something that is clearly not done now:
opentelemetry-python/ext/opentelemetry-ext-jaeger/src/opentelemetry/ext/jaeger/__init__.py
Lines 266 to 273 in 005575e
opentelemetry-python/ext/opentelemetry-ext-zipkin/src/opentelemetry/ext/zipkin/__init__.py
Lines 157 to 163 in 005575e
opentelemetry-python/ext/opentelemetry-ext-otcollector/src/opentelemetry/ext/otcollector/util.py
Lines 65 to 74 in 005575e
I'm aware of open-telemetry/opentelemetry-specification#425, the outcome appears to be that
numericrefers tointandfloattypes.This PR also handles the case of an empty key open-telemetry/opentelemetry-specification#459.
There are still some things this PR is not handling: