-
Notifications
You must be signed in to change notification settings - Fork 292
fix: Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions #2215
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -25,27 +25,34 @@ def numeric?(value) | |
| end | ||
|
|
||
| def valid_simple_value?(value) | ||
| value.instance_of?(String) || boolean?(value) || numeric?(value) | ||
| value.instance_of?(String) || boolean?(value) || numeric?(value) || value.nil? | ||
| end | ||
|
|
||
| def valid_array_value?(value) | ||
| return false unless value.is_a?(Array) | ||
| return true if value.empty? | ||
| def valid_value?(value) | ||
| to_check = [value] | ||
| seen = Set.new | ||
| until to_check.empty? | ||
|
Contributor
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. Thanks for updating this to comply latest spec. def valid_value?(value, depth = 0)
# ...
case value
when String, TrueClass, FalseClass, Integer, Float, NilClass
true
when Array
value.all? { |v| valid_value?(v, depth + 1) }
when Hash
value.all? { |k, v| valid_key?(k) && valid_value?(v, depth + 1) }
else
false
end
# ...
end
Contributor
Author
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. Yes, I originally used the recursive approach, but I was a bit concerned about larger more complex JSON style attributes, since there isn't a natural limit on nesting. |
||
| current = to_check.pop | ||
| next if valid_simple_value?(current) | ||
|
|
||
| case value.first | ||
| when String | ||
| value.all? { |v| v.instance_of?(String) } | ||
| when TrueClass, FalseClass | ||
| value.all? { |v| boolean?(v) } | ||
| when Numeric | ||
| value.all? { |v| numeric?(v) } | ||
| else | ||
| false | ||
| end | ||
| end | ||
| return false if seen.include?(current.object_id) | ||
|
|
||
| def valid_value?(value) | ||
| valid_simple_value?(value) || valid_array_value?(value) | ||
| seen << current.object_id | ||
|
|
||
| case current | ||
| when Array | ||
| current.each { |v| to_check << v } | ||
| when Hash | ||
| current.each do |k, v| | ||
| return false unless valid_key?(k) | ||
|
|
||
| to_check << v | ||
| end | ||
| else | ||
| return false | ||
| end | ||
| end | ||
| true | ||
| end | ||
|
|
||
| def valid_attributes?(owner, kind, attrs) | ||
|
|
||
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.
Could the string check be softened, either to allow descendants:
or duck type
the latter needs to be checked after other simple types