Skip to content

fix(redis): Use command_queue instead of command_stack if available #4404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion sentry_sdk/integrations/redis/_sync_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,21 @@ def sentry_patched_execute(self, *args, **kwargs):
origin=SPAN_ORIGIN,
) as span:
with capture_internal_exceptions():
command_seq = None
if getattr(self, "_execution_strategy", None) and getattr(
self._execution_strategy, "command_queue", None
):
command_seq = self._execution_strategy.command_queue
else:
command_seq = self.command_stack

set_db_data_fn(span, self)
_set_pipeline_data(
span,
is_cluster,
get_command_args_fn,
False if is_cluster else self.transaction,
self.command_stack,
command_seq,
)

return old_execute(self, *args, **kwargs)
Expand Down
10 changes: 7 additions & 3 deletions sentry_sdk/integrations/redis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ def _parse_rediscluster_command(command):


def _set_pipeline_data(
span, is_cluster, get_command_args_fn, is_transaction, command_stack
span,
is_cluster,
get_command_args_fn,
is_transaction,
commands_seq,
):
# type: (Span, bool, Any, bool, Sequence[Any]) -> None
span.set_tag("redis.is_cluster", is_cluster)
span.set_tag("redis.transaction", is_transaction)

commands = []
for i, arg in enumerate(command_stack):
for i, arg in enumerate(commands_seq):
if i >= _MAX_NUM_COMMANDS:
break

Expand All @@ -123,7 +127,7 @@ def _set_pipeline_data(
span.set_data(
"redis.commands",
{
"count": len(command_stack),
"count": len(commands_seq),
"first_ten": commands,
},
)
Expand Down
Loading