Skip to content

fix(pika): skip already-decorated callbacks in _instrument_channel_consumers#4726

Open
axelray-dev wants to merge 1 commit into
open-telemetry:mainfrom
axelray-dev:fix/pika-duplicate-consumer-spans
Open

fix(pika): skip already-decorated callbacks in _instrument_channel_consumers#4726
axelray-dev wants to merge 1 commit into
open-telemetry:mainfrom
axelray-dev:fix/pika-duplicate-consumer-spans

Conversation

@axelray-dev

Copy link
Copy Markdown

Description

When multiple basic_consume() calls are made on a single pika channel, each message produces duplicate (nested) CONSUMER spans -- N spans per message where N equals the number of consumers registered on the channel.

The root cause is that _instrument_channel_consumers() re-wraps every callback on each basic_consume() call without checking whether the callback is already decorated. The _original_callback attribute set on the decorated callback accumulates nested wrappers.

This adds a guard in _instrument_channel_consumers() to skip callbacks that already have an _original_callback attribute, indicating they were wrapped in a prior call.

Addresses #4667

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Added a regression test test_instrument_consumers_skips_already_decorated_callbacks that:

  1. Creates a channel with 2 consumer infos, each with a real callback function
  2. Calls _instrument_channel_consumers() twice (simulating two basic_consume() calls)
  3. Asserts _decorate_callback is called exactly 2 times (once per consumer, not 4)
  4. Asserts each callback's _original_callback still points to the original function
  • Test added

Does This PR Require a Core Repo Change?

  • Yes.
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

…nsumers

Addresses open-telemetry#4667: multiple basic_consume() calls on a single channel
cause duplicate nested CONSUMER spans because callbacks get re-wrapped
without checking if already decorated.

Assisted-by: Codex
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 21, 2026

Copy link
Copy Markdown

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

  • ✅ login: axelray-dev / name: axelray-dev (ee766cb)

@axelray-dev axelray-dev marked this pull request as ready for review June 21, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant