Skip to content

feat(redis): Add tags for more commands #733

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 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ sentry-sdk==0.10.1

A major release `N` implies the previous release `N-1` will no longer receive updates. We generally do not backport bugfixes to older versions unless they are security relevant. However, feel free to ask for backports of specific commits on the bugtracker.

## [Unreleased]

* Redis integration: add tags for more commands

## 0.15.1

* Fix fatal crash in Pyramid integration on 404.
Expand Down
13 changes: 11 additions & 2 deletions sentry_sdk/integrations/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
if MYPY:
from typing import Any

_SINGLE_KEY_COMMANDS = frozenset(
["decr", "decrby", "get", "incr", "incrby", "pttl", "set", "setex", "setnx", "ttl"]
)
_MULTI_KEY_COMMANDS = frozenset(["del", "touch", "unlink"])


class RedisIntegration(Integration):
identifier = "redis"
Expand Down Expand Up @@ -62,8 +67,12 @@ def sentry_patched_execute_command(self, name, *args, **kwargs):
if name:
span.set_tag("redis.command", name)

if name and args and name.lower() in ("get", "set", "setex", "setnx"):
span.set_tag("redis.key", args[0])
if name and args:
name_low = name.lower()
if (name_low in _SINGLE_KEY_COMMANDS) or (
name_low in _MULTI_KEY_COMMANDS and len(args) == 1
):
span.set_tag("redis.key", args[0])

return old_execute_command(self, name, *args, **kwargs)

Expand Down