Skip to content

Commit 08682f6

Browse files
shlee322Alex Boten
and
Alex Boten
authored
redis: fix default port KeyError, wrong attr name (#265)
* redis: fix default port KeyError, wrong attr name * fix docker tests and another ip/port issue in asyncpg Co-authored-by: Alex Boten <[email protected]>
1 parent 96b0f59 commit 08682f6

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
([#424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/424))
2121
- Update gRPC instrumentation to better wrap server context
2222
([#420](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/420))
23+
- `opentelemetry-instrumentation-redis` Fix default port KeyError and Wrong Attribute name (net.peer.ip -> net.peer.port)
24+
([#265](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/265))
25+
- `opentelemetry-instrumentation-asyncpg` Fix default port KeyError and Wrong Attribute name (net.peer.ip -> net.peer.port)
26+
([#265](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/265))
2327

2428
### Added
2529
- `opentelemetry-instrumentation-urllib3` Add urllib3 instrumentation

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict:
6868
addr = getattr(connection, "_addr", None)
6969
if isinstance(addr, tuple):
7070
span_attributes["net.peer.name"] = addr[0]
71-
span_attributes["net.peer.ip"] = addr[1]
71+
span_attributes["net.peer.port"] = addr[1]
7272
span_attributes["net.transport"] = "IP.TCP"
7373
elif isinstance(addr, str):
7474
span_attributes["net.peer.name"] = addr

instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def _extract_conn_attributes(conn_kwargs):
2626
attributes["db.name"] = db
2727
attributes["db.redis.database_index"] = db
2828
try:
29-
attributes["net.peer.name"] = conn_kwargs["host"]
30-
attributes["net.peer.ip"] = conn_kwargs["port"]
29+
attributes["net.peer.name"] = conn_kwargs.get("host", "localhost")
30+
attributes["net.peer.port"] = conn_kwargs.get("port", 6379)
3131
attributes["net.transport"] = "IP.TCP"
3232
except KeyError:
33-
attributes["net.peer.name"] = conn_kwargs["path"]
33+
attributes["net.peer.name"] = conn_kwargs.get("path", "")
3434
attributes["net.transport"] = "Unix"
3535

3636
return attributes

tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def check_span(self, span):
4646
self.assertEqual(span.attributes["db.name"], POSTGRES_DB_NAME)
4747
self.assertEqual(span.attributes["db.user"], POSTGRES_USER)
4848
self.assertEqual(span.attributes["net.peer.name"], POSTGRES_HOST)
49-
self.assertEqual(span.attributes["net.peer.ip"], POSTGRES_PORT)
49+
self.assertEqual(span.attributes["net.peer.port"], POSTGRES_PORT)
5050

5151
def test_instrumented_execute_method_without_arguments(self, *_, **__):
5252
async_call(self._connection.execute("SELECT 42;"))
@@ -148,7 +148,7 @@ def check_span(self, span):
148148
self.assertEqual(span.attributes["db.name"], POSTGRES_DB_NAME)
149149
self.assertEqual(span.attributes["db.user"], POSTGRES_USER)
150150
self.assertEqual(span.attributes["net.peer.name"], POSTGRES_HOST)
151-
self.assertEqual(span.attributes["net.peer.ip"], POSTGRES_PORT)
151+
self.assertEqual(span.attributes["net.peer.port"], POSTGRES_PORT)
152152

153153
def test_instrumented_execute_method_with_arguments(self, *_, **__):
154154
async_call(self._connection.execute("SELECT $1;", "1"))

tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _check_span(self, span, name):
3535
self.assertIs(span.status.status_code, trace.StatusCode.UNSET)
3636
self.assertEqual(span.attributes.get("db.name"), 0)
3737
self.assertEqual(span.attributes["net.peer.name"], "localhost")
38-
self.assertEqual(span.attributes["net.peer.ip"], 6379)
38+
self.assertEqual(span.attributes["net.peer.port"], 6379)
3939

4040
def test_long_command(self):
4141
self.redis_client.mget(*range(1000))
@@ -125,7 +125,7 @@ def _check_span(self, span, name):
125125
self.assertEqual(span.name, name)
126126
self.assertIs(span.status.status_code, trace.StatusCode.UNSET)
127127
self.assertEqual(span.attributes["net.peer.name"], "localhost")
128-
self.assertEqual(span.attributes["net.peer.ip"], 6379)
128+
self.assertEqual(span.attributes["net.peer.port"], 6379)
129129
self.assertEqual(span.attributes["db.redis.database_index"], 10)
130130

131131
def test_get(self):

0 commit comments

Comments
 (0)