Skip to content

Commit f783ecc

Browse files
committed
migrate attrs
1 parent 08e896a commit f783ecc

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

sentry_sdk/integrations/redis/modules/queries.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,24 +46,33 @@ def _get_db_span_description(
4646
def _set_db_data_on_span(
4747
span: "Union[Span, StreamedSpan]", connection_params: "dict[str, Any]"
4848
) -> None:
49+
db = connection_params.get("db")
50+
host = connection_params.get("host")
51+
port = connection_params.get("port")
52+
4953
if isinstance(span, StreamedSpan):
50-
set_on_span = span.set_attribute
51-
else:
52-
set_on_span = span.set_data
54+
span.set_attribute("db.system.name", "redis")
5355

54-
set_on_span(SPANDATA.DB_SYSTEM, "redis")
56+
if db is not None:
57+
span.set_attribute("db.namespace", str(db))
5558

56-
db = connection_params.get("db")
57-
if db is not None:
58-
set_on_span(SPANDATA.DB_NAME, str(db))
59+
if host is not None:
60+
span.set_attribute(SPANDATA.SERVER_ADDRESS, host)
5961

60-
host = connection_params.get("host")
61-
if host is not None:
62-
set_on_span(SPANDATA.SERVER_ADDRESS, host)
62+
if port is not None:
63+
span.set_attribute(SPANDATA.SERVER_PORT, port)
6364

64-
port = connection_params.get("port")
65-
if port is not None:
66-
set_on_span(SPANDATA.SERVER_PORT, port)
65+
else:
66+
span.set_data(SPANDATA.DB_SYSTEM, "redis")
67+
68+
if db is not None:
69+
span.set_data(SPANDATA.DB_NAME, str(db))
70+
71+
if host is not None:
72+
span.set_data(SPANDATA.SERVER_ADDRESS, host)
73+
74+
if port is not None:
75+
span.set_data(SPANDATA.SERVER_PORT, port)
6776

6877

6978
def _set_db_data(

0 commit comments

Comments
 (0)