Skip to content

[EXPORTER] Add bytes support for OTLP recordables #3495

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

Merged
merged 4 commits into from
Jun 30, 2025

Conversation

owent
Copy link
Member

@owent owent commented Jun 24, 2025

Fixes #3487

Changes

  • Add bytes support for OTLP recordables.

The API interface support long time ago, but after the protos are updated, we seem to forget to implement it.
See open-telemetry/opentelemetry-specification#780 and open-telemetry/opentelemetry-proto#297 for details.

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

@owent owent requested a review from a team as a code owner June 24, 2025 13:21
Copy link

netlify bot commented Jun 24, 2025

Deploy Preview for opentelemetry-cpp-api-docs canceled.

Name Link
🔨 Latest commit 55a31a3
🔍 Latest deploy log https://app.netlify.com/projects/opentelemetry-cpp-api-docs/deploys/6862ce2a2307800008bc60c6

Copy link

codecov bot commented Jun 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.96%. Comparing base (7059f73) to head (55a31a3).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3495      +/-   ##
==========================================
+ Coverage   89.95%   89.96%   +0.02%     
==========================================
  Files         219      219              
  Lines        7051     7051              
==========================================
+ Hits         6342     6343       +1     
+ Misses        709      708       -1     

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

Copy link
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@lalitb
Copy link
Member

lalitb commented Jun 24, 2025

Unfortunately, as a side effect, this change also enables support for populating byte/uint8 types as span attribute values, which is inconsistent with the specs:

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute

Per the spec, an attribute value MUST be one of the following:

  • string
  • boolean
  • double (IEEE 754)
  • signed 64-bit integer
  • Or an array of the above types (array must be homogeneous)

Supporting raw bytes or uint8 is not permitted for span attributes.

It’s better to enable populating uint8_t as OTLP attributes or body only for logs, not for spans.
Alternatively, instead of this PR, document that byte data should be encoded as base64 and set as a string attribute. The custom exporter or backend can handle base64 decoding if needed.

Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

As mentioned - #3495 (comment)

Fixes unit test: SetEmptyArrayAttribute

Fixes IWYU warnings

Only LogRecord accept bytes
@owent owent force-pushed the add_bytes_support_for_otlp branch from 777f951 to 310964d Compare June 25, 2025 09:31
@owent
Copy link
Member Author

owent commented Jun 25, 2025

Unfortunately, as a side effect, this change also enables support for populating byte/uint8 types as span attribute values, which is inconsistent with the specs:

https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/common/README.md#attribute

Per the spec, an attribute value MUST be one of the following:

  • string
  • boolean
  • double (IEEE 754)
  • signed 64-bit integer
  • Or an array of the above types (array must be homogeneous)

Supporting raw bytes or uint8 is not permitted for span attributes.

It’s better to enable populating uint8_t as OTLP attributes or body only for logs, not for spans. Alternatively, instead of this PR, document that byte data should be encoded as base64 and set as a string attribute. The custom exporter or backend can handle base64 decoding if needed.

Thanks, only log record use bytes now.

@owent owent requested a review from lalitb June 26, 2025 14:30
Copy link
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

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

Thanks.

@marcalff marcalff changed the title Add bytes support for OTLP recordables [EXPORTER] Add bytes support for OTLP recordables Jun 30, 2025
@marcalff marcalff merged commit 22715dd into open-telemetry:main Jun 30, 2025
70 of 71 checks passed
malkia added a commit to malkia/opentelemetry-cpp that referenced this pull request Jun 30, 2025
[EXPORTER] Add bytes support for OTLP recordables (open-telemetry#3495)
@owent owent deleted the add_bytes_support_for_otlp branch July 1, 2025 06:43
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.

Support bytes_value type for LogRecord Body
4 participants