Skip to content

[OTLP EXPORTER] Support setting byte arrays in all attribute collections and reject null keys#4226

Open
dbarker wants to merge 3 commits into
open-telemetry:mainfrom
dbarker:fix_otlp_attribute_spec_compliance_v2
Open

[OTLP EXPORTER] Support setting byte arrays in all attribute collections and reject null keys#4226
dbarker wants to merge 3 commits into
open-telemetry:mainfrom
dbarker:fix_otlp_attribute_spec_compliance_v2

Conversation

@dbarker

@dbarker dbarker commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes # (issue)

Fixes a few non-compliant areas of the otlp attribute spec:

  1. keys must not be null/empty
  2. byte arrays must be supported by all attribute collections

See:

https://opentelemetry.io/docs/specs/otel/common/#attribute

https://opentelemetry.io/docs/specs/otel/common/#attribute-collections

The attribute key MUST be a non-null and non-empty string.
Case sensitivity of keys is preserved. Keys that differ in casing are treated as distinct keys.
The attribute value MUST be one of types defined in AnyValue.

All attribute collections then must accept a byte array.
Resources, Instrumentation Scopes, Metric points, Spans, Span Events, Span Links and Log Records, contain a collection of attributes.

Changes

  • Reject empty keys when setting attributes
  • Deprecate the PopulateAttribute/PopulateAnyValue methods that take allow_bytes boolean as a third arg.
  • Add new PopulateAttribute/PopulateAnyValue overloads that accept a strongly typed AttributeValueLengthMax object as the third arg.
  • Add tests for the new methods
  • Update internal usage to use the new methods
  • Behavior changes from v1.27
    • Attributes with empty keys are rejected
    • Byte sequences are now valid attribute values for instruments, spans, resources, and instrumentation scopes.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

// overloads above.
OPENTELEMETRY_DEPRECATED_MESSAGE(
"allow_bytes is unused; use the AttributeValueMaxLength overload instead")
static void PopulateAnyValue(opentelemetry::proto::common::v1::AnyValue *proto_value,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Decided to deprecate these methods that take bool allow_bytes since allow_bytes is no longer needed, but we still need the max_length arg which will be new in version 1.28.

@dbarker dbarker marked this pull request as ready for review July 8, 2026 22:48
@dbarker dbarker requested a review from a team as a code owner July 8, 2026 22:48

// Test that updating a duplicate key does not consume an attribute slot or increment
// the dropped-attributes counter, even when the attribute limit is already reached.
TEST(OtlpRecordable, DISABLED_SetAttributeDeduplicateDoesNotIncrementDropped)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

These tests for duplicate attribute keys are added but disabled since OtlpRecordable will duplicate keys now.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.25352% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.81%. Comparing base (46298b6) to head (135289a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...xporters/otlp/src/otlp_populate_attribute_utils.cc 91.74% 10 Missing ⚠️
sdk/src/logs/multi_recordable.cc 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4226      +/-   ##
==========================================
+ Coverage   82.79%   82.81%   +0.03%     
==========================================
  Files         415      415              
  Lines       17452    17486      +34     
==========================================
+ Hits        14447    14480      +33     
- Misses       3005     3006       +1     
Files with missing lines Coverage Δ
...try/exporters/otlp/otlp_populate_attribute_utils.h 100.00% <100.00%> (ø)
exporters/otlp/src/otlp_log_recordable.cc 38.97% <100.00%> (+0.81%) ⬆️
exporters/otlp/src/otlp_metric_utils.cc 91.98% <100.00%> (-0.04%) ⬇️
exporters/otlp/src/otlp_recordable.cc 90.36% <100.00%> (+0.09%) ⬆️
sdk/src/trace/span.cc 89.10% <100.00%> (+0.21%) ⬆️
sdk/src/logs/multi_recordable.cc 90.00% <50.00%> (-1.13%) ⬇️
...xporters/otlp/src/otlp_populate_attribute_utils.cc 92.74% <91.74%> (-0.02%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant