opentelemetry-instrumentation-pika: prevent duplicate consumer spans#4740
opentelemetry-instrumentation-pika: prevent duplicate consumer spans#4740aivinay wants to merge 4 commits into
Conversation
|
|
9113ad2 to
50cdf3d
Compare
Skip re-wrapping consumer callbacks that have already been decorated by the Pika instrumentation, so repeated consumer registration does not stack wrappers. Assisted-by: OpenAI Codex
50cdf3d to
04505b5
Compare
herin049
left a comment
There was a problem hiding this comment.
Can we include a test case which is similar to the reproduction example in the original issue?
There was a problem hiding this comment.
Pull request overview
This PR updates the opentelemetry-instrumentation-pika consumer callback instrumentation to avoid re-wrapping callbacks that were already decorated, preventing stacked wrappers from emitting duplicate nested CONSUMER spans when basic_consume is invoked multiple times on the same channel.
Changes:
- Skip decorating consumer callbacks in
_instrument_channel_consumerswhen they already carry the_original_callbackmarker. - Adjust and add unit tests to verify already-decorated callbacks are not wrapped again.
- Add a changelog fragment documenting the fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py | Adds a guard to prevent double-wrapping already-instrumented consumer callbacks. |
| instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.py | Updates existing assertions and adds a targeted regression test for the duplicate-span scenario. |
| .changelog/4740.fixed | Records the bug fix in the changelog fragments. |
Thanks, @herin049! Added a regression test based on the issue reproduction: three consumers on one channel, one q1 delivery, and an assertion that only one q1 receive CONSUMER span is emitted. |
Description
Updates
opentelemetry-instrumentation-pikaso consumer callbacks that were already decorated by the instrumentation are not wrapped again when channel consumers are re-instrumented.This keeps newly registered consumers decorated while preventing stacked callback wrappers from producing duplicate consumer spans.
Fixes #4667
Type of change
How Has This Been Tested?
uvx --with tox-uv tox -e py314-test-instrumentation-sio-pika-1-wrapt2 -- instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.pyuvx --with tox-uv tox -e py314-test-instrumentation-sio-pika-0-wrapt1 -- instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.pyuvx --with tox-uv tox -e lint-instrumentation-sio-pikauvx ruff check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.pyuvx ruff format --check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.pyDoes This PR Require a Core Repo Change?
Checklist: