Skip to content

opentelemetry-api: truncate byte array attribute values according to spec - #5855

Open
DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:fix_attribute_value_parsing
Open

DylanRussell wants to merge 6 commits into
open-telemetry:mainfrom
DylanRussell:fix_attribute_value_parsing

Conversation

@DylanRussell

@DylanRussell DylanRussell commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Truncate bytes and bytearray attribute values to max_value_length in _clean_attribute_value as mandated by the OpenTelemetry Attribute Limits Specification. Mutable bytearray values are also converted to immutable bytes to preserve attribute immutability.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • I am a human and not a bot
  • I have run tox -e precommit
  • I have run tox -e typecheck
  • I have run the relevant tests and linting tox environments

…spec

Truncate bytes and bytearray attribute values to max_value_length as mandated by the OpenTelemetry Attribute Limits specification.

Assisted-by: Gemini
@DylanRussell
DylanRussell requested a review from a team as a code owner October 28, 2026 20:42
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-11-02 18:50 UTC

Merge when ready.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Remove redundant max_string_value_length parameter.

Assisted-by: Gemini

Copilot AI left a comment

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.

🟡 Changes recommended

Byte-array attribute cleaning can emit multiple limit warnings for a single record, violating the specification’s requirement of at most one limit diagnostic per record.

1 open issue
What changed in this PR

This PR extends the API’s attribute cleaner to apply value-length limits to byte arrays and convert mutable bytearray values to immutable bytes.

Changes:

  • Truncate byte-array values, including those nested in sequences and mappings.
  • Add tests for truncation and immutable conversion.
  • Update parameter documentation and add a changelog entry.
File Description
opentelemetry-api/​tests/​attributes/​test_attributes.py Adds byte-array truncation, conversion, and nested-value tests.
opentelemetry-api/​src/​opentelemetry/​attributes/​__init__.py Applies length limits to byte arrays and converts bytearray to bytes.
.changelog/​5855.fixed Documents the byte-array truncation fix.

Review effort: Balanced

This branch has not been deployed

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

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

3 participants