Skip to content

fix - Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions#2215

Open
0robustus1 wants to merge 2 commits into
open-telemetry:mainfrom
0robustus1:fix/spec-conform-attribute-type-validations
Open

fix - Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions#2215
0robustus1 wants to merge 2 commits into
open-telemetry:mainfrom
0robustus1:fix/spec-conform-attribute-type-validations

Conversation

@0robustus1

Copy link
Copy Markdown

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.

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.
@0robustus1 0robustus1 force-pushed the fix/spec-conform-attribute-type-validations branch from f46a1d8 to 8a45428 Compare July 3, 2026 11:50
@0robustus1 0robustus1 changed the title Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions fix/Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions Jul 3, 2026
@0robustus1 0robustus1 force-pushed the fix/spec-conform-attribute-type-validations branch from 8a45428 to 7c18f24 Compare July 3, 2026 15:12
@0robustus1 0robustus1 changed the title fix/Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions fix - Update attribute type conformance validations to be in line with current OpenTelemetry Semantic Conventions Jul 3, 2026
@0robustus1 0robustus1 force-pushed the fix/spec-conform-attribute-type-validations branch from 7c18f24 to 6f83a68 Compare July 3, 2026 16:00
def valid_value?(value)
to_check = [value]
seen = Set.new
until to_check.empty?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants