Skip to content

Commit c1ceb7b

Browse files
committed
fix(redis): extract ClusterPipeline commands from _execution_strategy in redis-py 6+
redis-py 6 refactored ClusterPipeline so that commands are appended to _execution_strategy.command_queue instead of instance.command_stack. The latter still exists but is never populated, causing pipeline spans to always show an empty command list. Prefer _execution_strategy.command_queue when it exists, falling back to the old command_stack / _command_stack attributes for older versions and non-cluster pipelines. Fixes #4084 Signed-off-by: alliasgher <alliasgher123@gmail.com>
1 parent 11e1867 commit c1ceb7b

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

  • instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,17 @@ def _build_span_meta_data_for_pipeline(
184184
instance: PipelineInstance | AsyncPipelineInstance,
185185
) -> tuple[list[Any], str, str]:
186186
try:
187-
command_stack = (
188-
instance.command_stack
189-
if hasattr(instance, "command_stack")
190-
else instance._command_stack
191-
)
187+
# redis-py 6+ ClusterPipeline stores commands on _execution_strategy.
188+
# Fall back to command_stack / _command_stack for older versions and
189+
# non-cluster pipelines.
190+
if hasattr(instance, "_execution_strategy") and hasattr(
191+
instance._execution_strategy, "command_queue"
192+
):
193+
command_stack = instance._execution_strategy.command_queue
194+
elif hasattr(instance, "command_stack"):
195+
command_stack = instance.command_stack
196+
else:
197+
command_stack = instance._command_stack
192198

193199
cmds = [
194200
_format_command_args(c.args if hasattr(c, "args") else c[0])

0 commit comments

Comments
 (0)