Skip to content

Commit 6c8e64e

Browse files
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 d83761f commit 6c8e64e

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Bump `pylint` to `4.0.5`
1717
([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244))
1818

19+
### Fixed
20+
21+
- `opentelemetry-instrumentation-pika` Use `ObjectProxy` instead of `BaseObjectProxy` for `ReadyMessagesDequeProxy` to restore iterability with wrapt 2.x
22+
([#4461](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4461))
23+
1924
### Breaking changes
2025

2126
- Drop Python 3.9 support

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)