fix - Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions#2215
Open
0robustus1 wants to merge 2 commits into
Conversation
According to https://opentelemetry.io/docs/specs/otel/common/#anyvalue (Introduced in v1.51.0 of the OTel Spec: https://github.com/open-telemetry/opentelemetry-specification/tree/v1.51.0/specification/common) an attribute value is defined as `AnyValue` with AnyValue being allowed to be a simple value as well as an Array of AnyValue (which includes nested arrays and mixed array), as well as map<string, AnyValue>. Empty values are allowed as well.
f46a1d8 to
8a45428
Compare
8a45428 to
7c18f24
Compare
7c18f24 to
6f83a68
Compare
xuan-cao-swi
reviewed
Jul 3, 2026
| def valid_value?(value) | ||
| to_check = [value] | ||
| seen = Set.new | ||
| until to_check.empty? |
Contributor
There was a problem hiding this comment.
Thanks for updating this to comply latest spec.
Have you considered using a recursive approach instead?
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
Author
There was a problem hiding this comment.
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.
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.
OpenTelemetry v1.51.0 introduced a wider definition of AnyValue. This PR aims to validate attribute values against that newer spec rather than the older one.