diff --git a/CHANGELOG.md b/CHANGELOG.md index 8818f8b070..21d1620fa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `pylint` to `4.0.5` ([#4244](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4244)) +### Fixed + +- `opentelemetry-instrumentation-redis`: Extract `ClusterPipeline` commands from `_execution_strategy` in redis-py 6+ so span attributes include the pipelined commands instead of being empty + ([#4436](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4436)) + ### Breaking changes - Drop Python 3.9 support diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py index 320758f842..e63379dd48 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py @@ -184,11 +184,17 @@ def _build_span_meta_data_for_pipeline( instance: PipelineInstance | AsyncPipelineInstance, ) -> tuple[list[Any], str, str]: try: - command_stack = ( - instance.command_stack - if hasattr(instance, "command_stack") - else instance._command_stack - ) + # redis-py 6+ ClusterPipeline stores commands on _execution_strategy. + # Fall back to command_stack / _command_stack for older versions and + # non-cluster pipelines. + if hasattr(instance, "_execution_strategy") and hasattr( + instance._execution_strategy, "command_queue" + ): + command_stack = instance._execution_strategy.command_queue + elif hasattr(instance, "command_stack"): + command_stack = instance.command_stack + else: + command_stack = instance._command_stack cmds = [ _format_command_args(c.args if hasattr(c, "args") else c[0])