Skip to content

fix(redis): build ClusterPipeline span metadata from _execution_strategy in redis-py 6+#4728

Open
UTKARSH698 wants to merge 2 commits into
open-telemetry:mainfrom
UTKARSH698:fix-redis-cluster-pipeline-span-4084
Open

fix(redis): build ClusterPipeline span metadata from _execution_strategy in redis-py 6+#4728
UTKARSH698 wants to merge 2 commits into
open-telemetry:mainfrom
UTKARSH698:fix-redis-cluster-pipeline-span-4084

Conversation

@UTKARSH698

Copy link
Copy Markdown

Description

redis-py 6 refactored ClusterPipeline so that queued commands are no longer appended to command_stack (which still exists but stays empty); they are now tracked on _execution_strategy.command_queue. Because _build_span_meta_data_for_pipeline read commands from command_stack, ClusterPipeline spans under redis-py 6+ were emitted with an empty db.statement and a db.redis.pipeline_length of 0.

This change makes _build_span_meta_data_for_pipeline read commands from _execution_strategy.command_queue when present, falling back to command_stack / _command_stack for non-cluster pipelines and older redis-py versions.

This revives the approach from #4436 (closed by the stale bot for inactivity after a maintainer reviewed it positively) and adds the changelog fragment via towncrier.

Fixes #4084

Type of change

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

How Has This Been Tested?

  • Added TestBuildSpanMetaDataForPipeline unit tests covering the redis-py 6+ cluster pipeline path (commands read from _execution_strategy.command_queue), a regression test for the legacy command_stack path, and the empty-pipeline fallback to a redis span name.
  • Full redis instrumentation test suite passes locally (pytest for opentelemetry-instrumentation-redis).
  • ruff check and ruff format --check clean.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

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

…egy in redis-py 6+

redis-py 6 refactored ClusterPipeline so that queued commands are no
longer appended to `command_stack`; they now live on
`_execution_strategy.command_queue`. As a result the redis instrumentor
emitted ClusterPipeline spans with an empty DB_STATEMENT and a
`db.redis.pipeline_length` of 0.

`_build_span_meta_data_for_pipeline` now reads commands from
`_execution_strategy.command_queue` when present, falling back to
`command_stack` / `_command_stack` for non-cluster pipelines and older
redis-py versions.

Fixes open-telemetry#4084
@UTKARSH698 UTKARSH698 requested a review from a team as a code owner June 22, 2026 05:32
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 22, 2026

Copy link
Copy Markdown

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

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.

Redis instrumentor doesn't correctly build span metadata for cluster pipelines in redis > 6.x

1 participant