Skip to content

Commit 50ff60b

Browse files
committed
Call set_db_data everywhere
1 parent c047640 commit 50ff60b

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

sentry_sdk/integrations/redis/__init__.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,18 @@ def _set_client_data(span, is_cluster, name, *args):
121121
def _set_db_data(span, connection_params):
122122
# type: (Span, Dict[str, Any]) -> None
123123
span.set_data(SPANDATA.DB_SYSTEM, "redis")
124-
span.set_data(SPANDATA.DB_NAME, text_type(connection_params.get("db")))
125-
span.set_data(SPANDATA.SERVER_ADDRESS, connection_params.get("host"))
126-
span.set_data(SPANDATA.SERVER_PORT, connection_params.get("port"))
124+
125+
db = connection_params.get("db")
126+
if db is not None:
127+
span.set_data(SPANDATA.DB_NAME, text_type(db))
128+
129+
host = connection_params.get("host")
130+
if host is not None:
131+
span.set_data(SPANDATA.SERVER_ADDRESS, host)
132+
133+
port = connection_params.get("port")
134+
if port is not None:
135+
span.set_data(SPANDATA.SERVER_PORT, port)
127136

128137

129138
def patch_redis_pipeline(pipeline_cls, is_cluster, get_command_args_fn):
@@ -140,20 +149,15 @@ def sentry_patched_execute(self, *args, **kwargs):
140149
with hub.start_span(
141150
op=OP.DB_REDIS, description="redis.pipeline.execute"
142151
) as span:
143-
# with capture_internal_exceptions():
144-
# import ipdb; ipdb.set_trace()
145-
print("#####################################")
146-
print(dir(self.connection_pool))
147-
print("#####################################")
148-
print(self.connection_pool)
149-
_set_db_data(span, self.connection_pool.connection_kwargs)
150-
_set_pipeline_data(
151-
span,
152-
is_cluster,
153-
get_command_args_fn,
154-
self.transaction,
155-
self.command_stack,
156-
)
152+
with capture_internal_exceptions():
153+
_set_db_data(span, self.connection_pool.connection_kwargs)
154+
_set_pipeline_data(
155+
span,
156+
is_cluster,
157+
get_command_args_fn,
158+
self.transaction,
159+
self.command_stack,
160+
)
157161

158162
return old_execute(self, *args, **kwargs)
159163

sentry_sdk/integrations/redis/asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
_get_redis_command_args,
88
_get_span_description,
99
_set_client_data,
10+
_set_db_data,
1011
_set_pipeline_data,
1112
)
1213
from sentry_sdk._types import TYPE_CHECKING
@@ -31,6 +32,7 @@ async def _sentry_execute(self, *args, **kwargs):
3132
op=OP.DB_REDIS, description="redis.pipeline.execute"
3233
) as span:
3334
with capture_internal_exceptions():
35+
_set_db_data(span, self.connection_pool.connection_kwargs)
3436
_set_pipeline_data(
3537
span,
3638
False,
@@ -58,6 +60,7 @@ async def _sentry_execute_command(self, name, *args, **kwargs):
5860
description = _get_span_description(name, *args)
5961

6062
with hub.start_span(op=OP.DB_REDIS, description=description) as span:
63+
_set_db_data(span, self.connection_pool.connection_kwargs)
6164
_set_client_data(span, False, name, *args)
6265

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

0 commit comments

Comments
 (0)