Skip to content

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

Open
dbarker wants to merge 18 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 18 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
  • In PopulateAttribute/PopulateAnyValue methods parameters:
    • remove allow_bytes
    • add a strongly typed AttributeValueLengthMax object
  • Add tests for the modified methods
  • Update internal usage to use the new parameters
  • Behavior changes from v1.28
    • 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

@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 96.62162% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.23%. Comparing base (3e4296e) to head (f25314d).

Files with missing lines Patch % Lines
...xporters/otlp/src/otlp_populate_attribute_utils.cc 98.25% 2 Missing ⚠️
...include/opentelemetry/sdk/common/attribute_utils.h 77.78% 2 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   78.15%   78.23%   +0.08%     
==========================================
  Files         440      440              
  Lines       18736    18768      +32     
==========================================
+ Hits        14642    14681      +39     
+ Misses       4094     4087       -7     
Files with missing lines Coverage Δ
...try/exporters/otlp/otlp_populate_attribute_utils.h 100.00% <100.00%> (ø)
exporters/otlp/src/otlp_log_recordable.cc 39.75% <100.00%> (+1.59%) ⬆️
exporters/otlp/src/otlp_metric_utils.cc 91.98% <100.00%> (-0.04%) ⬇️
exporters/otlp/src/otlp_recordable.cc 91.27% <100.00%> (+0.15%) ⬆️
sdk/src/trace/span.cc 93.70% <100.00%> (+0.12%) ⬆️
sdk/src/logs/multi_recordable.cc 90.00% <50.00%> (-1.13%) ⬇️
...xporters/otlp/src/otlp_populate_attribute_utils.cc 96.99% <98.25%> (+4.23%) ⬆️
...include/opentelemetry/sdk/common/attribute_utils.h 95.63% <77.78%> (+0.21%) ⬆️

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

Comment thread exporters/otlp/src/otlp_populate_attribute_utils.cc Outdated
@dbarker

dbarker commented Jul 15, 2026

Copy link
Copy Markdown
Member Author

Hi @owent Thanks for initial feedback. Can you take another review pass?

Comment thread exporters/otlp/src/otlp_populate_attribute_utils.cc Outdated

@owent owent left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's still an unnecessary conversion, but it's harmless. The rest LGTM. Thanks.

@marcalff marcalff added the pr:do-not-merge This PR is not ready to be merged. label Jul 16, 2026
@marcalff

Copy link
Copy Markdown
Member

do-not-merge label: to merge after the release of opentelemetry-cpp 1.28.0

@marcalff marcalff removed the pr:do-not-merge This PR is not ready to be merged. label Jul 16, 2026
dbarker and others added 3 commits July 17, 2026 12:36
…method to handle exceptions from nost::visit. remove unnecessary static casts in the attribute value visitors
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.

3 participants