Skip to content

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

Merged
aabmass merged 6 commits into
open-telemetry:mainfrom
DylanRussell:fix_attribute_value_parsing
Nov 5, 2026
Merged

aabmass merged 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

Merged · refreshed 2026-11-05 19:22 UTC

Status above doesn't look right?
  • 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

@aabmass
aabmass added this pull request to the merge queue Nov 5, 2026
Merged via the queue into open-telemetry:main with commit ba48fef Nov 5, 2026
580 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants