Skip to content

Added guard against negative value of max_value_len - #5647

Merged
xrmx merged 4 commits into
open-telemetry:mainfrom
GauravR31:issue-5646
Sep 16, 2026
Merged

xrmx merged 4 commits into
open-telemetry:mainfrom
GauravR31:issue-5646

Conversation

@GauravR31

@GauravR31 GauravR31 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

Previously, passing a negative value for max_value_len when initializing BoundedAttributes leads to Python string slicing (value[:max_value_len]) chopping characters off the end of strings instead of enforcing length limits, while logging misleading warning messages.
There was no check for a negative value, this PR adds this to the BoundedAttributes constructor.

Fixes #5646

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

Before

from opentelemetry.attributes import BoundedAttributes
ba = BoundedAttributes(max_value_len=-2, immutable=False)
ba["test_key"] = "hello world"
print(dict(ba))

No ValueError is raised during __init__. The string is truncated unexpectedly from the right ({'test_key': 'hello wor'}), and an invalid warning log is emitted (String attribute value exceeds max length of -2, truncating.).

After

from opentelemetry.attributes import BoundedAttributes
ba = BoundedAttributes(max_value_len=-2, immutable=False)

    raise ValueError("max_value_len must be valid int greater or equal to 0")
ValueError: max_value_len must be valid int greater or equal to 0

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@GauravR31
GauravR31 requested a review from a team as a code owner September 9, 2026 22:55
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 9, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@GauravR31 GauravR31 changed the title Added guard for max_value_len Added guard against negative value of max_value_len Sep 9, 2026
@github-project-automation github-project-automation Bot moved this to Approved PRs in Python PR digest Sep 9, 2026
@lzchen

lzchen commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

@GauravR31

Please rename changelog for the PR not the ISSUE. (.changelog/5647.fixed)

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 10, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on maintainers · refreshed 2026-09-14 18:43 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.

@GauravR31

Copy link
Copy Markdown
Contributor Author

@lzchen Thanks for catching that, have renamed the changelog accordingly

@lzchen
lzchen enabled auto-merge September 15, 2026 15:36
@GauravR31 GauravR31 closed this Sep 15, 2026
auto-merge was automatically disabled September 15, 2026 23:07

Pull request was closed

@GauravR31 GauravR31 reopened this Sep 15, 2026
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Sep 15, 2026
@xrmx xrmx moved this from Done to Approved PRs in Python PR digest Sep 16, 2026
@xrmx
xrmx enabled auto-merge September 16, 2026 07:37
@xrmx
xrmx added this pull request to the merge queue Sep 16, 2026
Merged via the queue into open-telemetry:main with commit 34c5e5f Sep 16, 2026
2298 of 2304 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Sep 16, 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.

[bug] BoundedAttributes missing negative value validation for max_value_len parameter

5 participants