From 727a3d1a8423edb45c597d4f8d7ae2f4f0bda3a9 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 25 Apr 2023 14:18:18 +0200 Subject: [PATCH] Add `db.system` data to redis db spans (#2038) --- sentry_sdk/integrations/redis.py | 3 ++- tests/integrations/redis/test_redis.py | 4 +++- tests/integrations/rediscluster/test_rediscluster.py | 4 +++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/integrations/redis.py b/sentry_sdk/integrations/redis.py index 3deae7483b..8d196d00b2 100644 --- a/sentry_sdk/integrations/redis.py +++ b/sentry_sdk/integrations/redis.py @@ -1,7 +1,7 @@ from __future__ import absolute_import from sentry_sdk import Hub -from sentry_sdk.consts import OP +from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.hub import _should_send_default_pii from sentry_sdk.utils import ( SENSITIVE_DATA_SUBSTITUTE, @@ -63,6 +63,7 @@ def sentry_patched_execute(self, *args, **kwargs): "redis.commands", {"count": len(self.command_stack), "first_ten": commands}, ) + span.set_data(SPANDATA.DB_SYSTEM, "redis") return old_execute(self, *args, **kwargs) diff --git a/tests/integrations/redis/test_redis.py b/tests/integrations/redis/test_redis.py index 657ba1527f..beb7901122 100644 --- a/tests/integrations/redis/test_redis.py +++ b/tests/integrations/redis/test_redis.py @@ -1,6 +1,7 @@ import mock from sentry_sdk import capture_message, start_transaction +from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations.redis import RedisIntegration from fakeredis import FakeStrictRedis @@ -53,7 +54,8 @@ def test_redis_pipeline(sentry_init, capture_events, is_transaction): "redis.commands": { "count": 3, "first_ten": ["GET 'foo'", "SET 'bar' 1", "SET 'baz' 2"], - } + }, + SPANDATA.DB_SYSTEM: "redis", } assert span["tags"] == { "redis.transaction": is_transaction, diff --git a/tests/integrations/rediscluster/test_rediscluster.py b/tests/integrations/rediscluster/test_rediscluster.py index 6c7e5f90a4..6425ca15e6 100644 --- a/tests/integrations/rediscluster/test_rediscluster.py +++ b/tests/integrations/rediscluster/test_rediscluster.py @@ -1,5 +1,6 @@ import pytest from sentry_sdk import capture_message +from sentry_sdk.consts import SPANDATA from sentry_sdk.api import start_transaction from sentry_sdk.integrations.redis import RedisIntegration @@ -71,7 +72,8 @@ def test_rediscluster_pipeline(sentry_init, capture_events): "redis.commands": { "count": 3, "first_ten": ["GET 'foo'", "SET 'bar' 1", "SET 'baz' 2"], - } + }, + SPANDATA.DB_SYSTEM: "redis", } assert span["tags"] == { "redis.transaction": False, # For Cluster, this is always False