Skip to content

opentelemetry-api: prevent recursive attribute value crashes - #5983

Open
csw7777 wants to merge 2 commits into
open-telemetry:mainfrom
csw7777:fix/attribute-nesting-depth-assisted
Open

csw7777 wants to merge 2 commits into
open-telemetry:mainfrom
csw7777:fix/attribute-nesting-depth-assisted

Conversation

@csw7777

@csw7777 csw7777 commented Nov 29, 2026

Copy link
Copy Markdown

Replaces #5976. Uses OpenTelemetry's Assisted-by AI disclosure convention while retaining csw7777 as the sole human commit author.

Summary

Fixes #5564.

  • Track active ancestor container IDs to reject cycles immediately, avoiding exponential traversal for branching cycles while allowing non-cyclic shared references.
  • Bound recursive attribute cleaning to 20 levels, replacing excessively nested values with None instead of leaking RecursionError into application code.
  • Clean top-level attribute values independently so an invalid value does not discard valid siblings.
  • Apply the same isolation to metric Measurement attributes.
  • Add regression coverage for cyclic sequences and mappings, the exact depth boundary, spans, resources, BoundedAttributes, and metric measurements.

This follows the 20-level approach previously reviewed in #5565 and #5757. In particular, it adds the metrics regression coverage requested in #5757 and reapplies the fix onto current main.

Compatibility

Only values that previously caused RecursionError are affected. Valid values at the supported depth remain intact, and valid sibling attributes are preserved. A warning is emitted when a value is replaced with None.

Validation

  • Focused API/SDK suites: 97 passed, 16 subtests passed.
  • The 12 new regression tests all pass.
  • ruff format and ruff check on every changed Python file: passed.
  • pylint on every changed Python file: passed, 10.00/10.

The focused suites were:

python -m pytest opentelemetry-api/tests/attributes \
  opentelemetry-sdk/tests/test_attribute_nesting_depth.py \
  opentelemetry-sdk/tests/metrics/test_metrics.py -q -o addopts=""

🤖 Generated with Kimi

Bound attribute nesting at 20 levels and replace cyclic or deeper values
with None. Clean top-level attributes independently so invalid values do not
discard valid siblings in spans, resources, and metric measurements.

Add API, SDK, resource, and measurement regression tests.

Fixes open-telemetry#5564

Assisted-by: Kimi
@csw7777
csw7777 requested a review from a team as a code owner November 29, 2026 05:32
@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-29 05:33 UTC

Review the latest changes.

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.
  • Should this be with the author? Comment /dashboard route:author to route it back.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

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: No status

Development

Successfully merging this pull request may close these issues.

Self-referential attribute value crashes the instrumented application with RecursionError

1 participant