Skip to content

Commit f006705

Browse files
MikeGoldsmithxrmx
authored andcommitted
fix(pika): use ObjectProxy for ReadyMessagesDequeProxy to restore iterability with wrapt 2.x (#4461)
* use ObjectProxy for pika ReadyMessagesDequeProxy to restore iterability wrapt 2.x BaseObjectProxy does not proxy __iter__, breaking iteration over the wrapped deque. Switch to ObjectProxy which proxies all dunder methods including __iter__. Assisted-by: Claude Opus 4.6 * update changelog with PR number Assisted-by: Claude Opus 4.6 * fix lint: import ordering and formatting Assisted-by: Claude Opus 4.6
1 parent 5e5a9ee commit f006705

3 files changed

Lines changed: 13 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515

1616
- `opentelemetry-instrumentation-dbapi` Use `ObjectProxy` instead of `BaseObjectProxy` for `TracedCursorProxy` to restore iterability with wrapt 2.x
1717
([#4427](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4427))
18+
- `opentelemetry-instrumentation-pika` Use `ObjectProxy` instead of `BaseObjectProxy` for `ReadyMessagesDequeProxy` to restore iterability with wrapt 2.x
19+
([#4461](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4461))
1820

1921
## Version 1.41.0/0.62b0 (2026-04-09)
2022

instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/utils.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77
)
88
from pika.channel import Channel
99
from pika.spec import Basic, BasicProperties
10-
11-
try:
12-
# wrapt 2.0.0+
13-
from wrapt import BaseObjectProxy # pylint: disable=no-name-in-module
14-
except ImportError:
15-
from wrapt import ObjectProxy as BaseObjectProxy
10+
from wrapt import ObjectProxy
1611

1712
from opentelemetry import context, propagate, trace
1813
from opentelemetry.instrumentation.utils import is_instrumentation_enabled
@@ -201,7 +196,7 @@ def _enrich_span(
201196

202197

203198
# pylint:disable=abstract-method
204-
class ReadyMessagesDequeProxy(BaseObjectProxy):
199+
class ReadyMessagesDequeProxy(ObjectProxy):
205200
def __init__(
206201
self,
207202
wrapped,

instrumentation/opentelemetry-instrumentation-pika/tests/test_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,3 +568,12 @@ def test_decorate_deque_proxy(
568568
get_span.assert_not_called()
569569
consume_hook.assert_not_called()
570570
returned_span.end.assert_not_called()
571+
572+
def test_deque_proxy_is_iterable(self) -> None:
573+
deque = collections.deque([1, 2, 3])
574+
generator_info = mock.MagicMock(
575+
spec=_QueueConsumerGeneratorInfo,
576+
consumer_tag="mock_task_name",
577+
)
578+
proxy = utils.ReadyMessagesDequeProxy(deque, generator_info, None)
579+
self.assertEqual(list(proxy), [1, 2, 3])

0 commit comments

Comments
 (0)