Skip to content

opentelemetry-instrumentation-pika: prevent duplicate consumer spans - #4740

Merged
xrmx merged 5 commits into
open-telemetry:mainfrom
aivinay:fix-pika-duplicate-consumer-spans
Jul 6, 2026
Merged

xrmx merged 5 commits into
open-telemetry:mainfrom
aivinay:fix-pika-duplicate-consumer-spans

Conversation

@aivinay

@aivinay aivinay commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

Updates opentelemetry-instrumentation-pika so 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

  • Bug fix (non-breaking change which fixes an issue)

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.py
  • uvx --with tox-uv tox -e py314-test-instrumentation-sio-pika-0-wrapt1 -- instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.py
  • uvx --with tox-uv tox -e lint-instrumentation-sio-pika
  • uvx ruff check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.py
  • uvx ruff format --check instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py instrumentation/opentelemetry-instrumentation-pika/tests/test_pika_instrumentation.py

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation update is not required

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 25, 2026 •

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: aivinay / name: Vinay Gupta (5fe700f)

@aivinay
aivinay force-pushed the fix-pika-duplicate-consumer-spans branch 2 times, most recently from 9113ad2 to 50cdf3d Compare June 25, 2026 13:28
@aivinay
aivinay marked this pull request as ready for review June 25, 2026 13:40
@aivinay
aivinay requested a review from a team as a code owner June 25, 2026 13:40
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
@aivinay
aivinay force-pushed the fix-pika-duplicate-consumer-spans branch from 50cdf3d to 04505b5 Compare June 26, 2026 17:38

@herin049 herin049 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include a test case which is similar to the reproduction example in the original issue?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_consumers when they already carry the _original_callback marker.
  • 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.

@aivinay

aivinay commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Can we include a test case which is similar to the reproduction example in the original issue?

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.

@xrmx

xrmx commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

I feel like the second test may be converted to a docker tests instead but we can do that as a followup.

@xrmx
xrmx enabled auto-merge July 6, 2026 09:51
@xrmx
xrmx added this pull request to the merge queue Jul 6, 2026
Merged via the queue into open-telemetry:main with commit 6b55f82 Jul 6, 2026
760 checks passed
@github-project-automation github-project-automation Bot moved this from Approved PRs to Done in Python PR digest Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

pika-instrumentation; Multiple basic_consume calls on one channel produce duplicate (nested) CONSUMER spans

5 participants