opentelemetry-instrumentation-pika: avoid duplicate consumer wrapping#4670
Open
popsiclelmlm wants to merge 1 commit into
Open
opentelemetry-instrumentation-pika: avoid duplicate consumer wrapping#4670popsiclelmlm wants to merge 1 commit into
popsiclelmlm wants to merge 1 commit into
Conversation
Assisted-by: GPT-5 Codex
herin049
approved these changes
Jun 9, 2026
herin049
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me, just a few small comments.
Comment on lines
+61
to
+63
| if "_original_callback" in getattr( | ||
| consumer_callback, "__dict__", {} | ||
| ): |
Contributor
There was a problem hiding this comment.
Why not just?
Suggested change
| if "_original_callback" in getattr( | |
| consumer_callback, "__dict__", {} | |
| ): | |
| if hasattr(consumer_callback, "_original_callback"): |
| if "_original_callback" in getattr( | ||
| consumer_callback, "__dict__", {} | ||
| ): | ||
| continue |
Contributor
There was a problem hiding this comment.
It also might be worth adding a warning log here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #4667.
Summary
Avoid wrapping an already-instrumented pika consumer callback again when
_instrument_channel_consumersruns more than once for the same channel.Reproduction
A
BlockingChannelcan callbasic_consumemultiple times. The instrumentation reruns_instrument_channel_consumersafter each registration. The new regression test calls_instrument_channel_consumerstwice for the same channel and asserts the callback remains the first decorated function.Root cause
_instrument_channel_consumersdecorated every callback in the channel consumer map each time it ran. Previously registered callbacks could therefore accumulate nested consumer span wrappers.Changes
_original_callbackmetadata.BlockingChannel.Tests
.venv-tox/bin/tox -e py314-test-instrumentation-sio-pika-1-wrapt2.venv-tox/bin/tox -e py314-test-instrumentation-sio-pika-0-wrapt2.venv-tox/bin/tox -e lint-instrumentation-sio-pika.tox/lint-instrumentation-sio-pika/bin/ruff check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.py.tox/lint-instrumentation-sio-pika/bin/ruff format --check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.pygit diff --checkScreenshots/Logs
N/A. This is a unit-level instrumentation fix.
Type of change
Does This PR Require a Core Repo Change?
Checklist: