From 3939111a1fdf7fc5d2a3df9ae31cc7b3ffa45d1b Mon Sep 17 00:00:00 2001 From: Alexander Shadchin Date: Fri, 3 May 2024 09:35:28 +0300 Subject: [PATCH] Fix net peer attribute for unix socket connection --- .../src/opentelemetry/instrumentation/redis/util.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py index 2a24ead79a..4703bc271f 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py @@ -29,7 +29,12 @@ def _extract_conn_attributes(conn_kwargs): } db = conn_kwargs.get("db", 0) attributes[SpanAttributes.DB_REDIS_DATABASE_INDEX] = db - try: + if "path" in conn_kwargs: + attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get("path", "") + attributes[SpanAttributes.NET_TRANSPORT] = ( + NetTransportValues.OTHER.value + ) + else: attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get( "host", "localhost" ) @@ -39,11 +44,6 @@ def _extract_conn_attributes(conn_kwargs): attributes[SpanAttributes.NET_TRANSPORT] = ( NetTransportValues.IP_TCP.value ) - except KeyError: - attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get("path", "") - attributes[SpanAttributes.NET_TRANSPORT] = ( - NetTransportValues.OTHER.value - ) return attributes