Repository navigation
Conversation
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 Co-Authored-By: Kimi <noreply@anthropic.com>
Assisted-by: Kimi Co-Authored-By: Kimi <noreply@anthropic.com>
|
Pull request dashboard statusClosed · refreshed 2026-11-29 05:33 UTC Status above doesn't look right?
|
givemehat
left a comment
There was a problem hiding this comment.
Nice catch on isolating top-level attributes via _clean_attributes so sibling attributes are preserved!
One edge case to consider in _clean_attribute_value_impl: relying solely on depth > _MAX_NESTING_DEPTH (20) to stop cycles means a cyclic structure with a branching factor of 2+ (e.g., d = {}; d['a'] = d; d['b'] = d) will still traverse
Tracking active ancestor container id(value)s in a seen: set[int] (adding before recursing into a Sequence/Mapping and removing in a finally block so non-cyclic shared references/DAGs remain allowed) would catch cycles immediately in _MAX_NESTING_DEPTH for non-cyclic deep nesting.
Track active ancestor container IDs to avoid exponential traversal for branching cycles while preserving non-cyclic shared references. Add regression coverage for both cases. Assisted-by: Kimi Co-Authored-By: Kimi <noreply@anthropic.com>
|
My account csw7777 is now authorized by EasyCLA. The remaining failure is for the AI co-author trailer |
Thank you for pointing out the issue. It has been fixed in commit 71b7741: before traversing a Sequence/Mapping, we record the ID of each active ancestor and remove it in a finally block after the recursive return, and if a duplicated ancestor is found, we reject it immediately so that branch cycles will not expand exponentially. Non-cyclic shared references are still allowed, and we have added two sets of regression tests, one for branch cycles and one for shared DAGs. Please take another look when you have time. |
Summary
Fixes #5564.
Noneinstead of leakingRecursionErrorinto application code.Measurementattributes.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
RecursionErrorare affected. Valid values at the supported depth remain intact, and valid sibling attributes are preserved. A warning is emitted when a value is replaced withNone.Validation
ruff formatandruff checkon every changed Python file: passed.pylinton 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
CLA
csw7777has completed EasyCLA authorization; re-evaluation requested.