diff --git a/CHANGELOG.md b/CHANGELOG.md index 6efcc6383c..89b8bd039a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#424](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/424)) - Update gRPC instrumentation to better wrap server context ([#420](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/420)) +- `opentelemetry-instrumentation-redis` Fix default port KeyError and Wrong Attribute name (net.peer.ip -> net.peer.port) + ([#265](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/265)) +- `opentelemetry-instrumentation-asyncpg` Fix default port KeyError and Wrong Attribute name (net.peer.ip -> net.peer.port) + ([#265](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/265)) ### Added - `opentelemetry-instrumentation-urllib3` Add urllib3 instrumentation diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py index e78224a9ef..0a558cb3d5 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py @@ -68,7 +68,7 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict: addr = getattr(connection, "_addr", None) if isinstance(addr, tuple): span_attributes["net.peer.name"] = addr[0] - span_attributes["net.peer.ip"] = addr[1] + span_attributes["net.peer.port"] = addr[1] span_attributes["net.transport"] = "IP.TCP" elif isinstance(addr, str): span_attributes["net.peer.name"] = addr 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 8898dab9f8..5679f29945 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py @@ -26,11 +26,11 @@ def _extract_conn_attributes(conn_kwargs): attributes["db.name"] = db attributes["db.redis.database_index"] = db try: - attributes["net.peer.name"] = conn_kwargs["host"] - attributes["net.peer.ip"] = conn_kwargs["port"] + attributes["net.peer.name"] = conn_kwargs.get("host", "localhost") + attributes["net.peer.port"] = conn_kwargs.get("port", 6379) attributes["net.transport"] = "IP.TCP" except KeyError: - attributes["net.peer.name"] = conn_kwargs["path"] + attributes["net.peer.name"] = conn_kwargs.get("path", "") attributes["net.transport"] = "Unix" return attributes diff --git a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py index 25e3b6a410..f7c7ba553c 100644 --- a/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/asyncpg/test_asyncpg_functional.py @@ -46,7 +46,7 @@ def check_span(self, span): self.assertEqual(span.attributes["db.name"], POSTGRES_DB_NAME) self.assertEqual(span.attributes["db.user"], POSTGRES_USER) self.assertEqual(span.attributes["net.peer.name"], POSTGRES_HOST) - self.assertEqual(span.attributes["net.peer.ip"], POSTGRES_PORT) + self.assertEqual(span.attributes["net.peer.port"], POSTGRES_PORT) def test_instrumented_execute_method_without_arguments(self, *_, **__): async_call(self._connection.execute("SELECT 42;")) @@ -148,7 +148,7 @@ def check_span(self, span): self.assertEqual(span.attributes["db.name"], POSTGRES_DB_NAME) self.assertEqual(span.attributes["db.user"], POSTGRES_USER) self.assertEqual(span.attributes["net.peer.name"], POSTGRES_HOST) - self.assertEqual(span.attributes["net.peer.ip"], POSTGRES_PORT) + self.assertEqual(span.attributes["net.peer.port"], POSTGRES_PORT) def test_instrumented_execute_method_with_arguments(self, *_, **__): async_call(self._connection.execute("SELECT $1;", "1")) diff --git a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py index 8cdbb8c4af..06a54b90ae 100644 --- a/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py +++ b/tests/opentelemetry-docker-tests/tests/redis/test_redis_functional.py @@ -35,7 +35,7 @@ def _check_span(self, span, name): self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertEqual(span.attributes.get("db.name"), 0) self.assertEqual(span.attributes["net.peer.name"], "localhost") - self.assertEqual(span.attributes["net.peer.ip"], 6379) + self.assertEqual(span.attributes["net.peer.port"], 6379) def test_long_command(self): self.redis_client.mget(*range(1000)) @@ -125,7 +125,7 @@ def _check_span(self, span, name): self.assertEqual(span.name, name) self.assertIs(span.status.status_code, trace.StatusCode.UNSET) self.assertEqual(span.attributes["net.peer.name"], "localhost") - self.assertEqual(span.attributes["net.peer.ip"], 6379) + self.assertEqual(span.attributes["net.peer.port"], 6379) self.assertEqual(span.attributes["db.redis.database_index"], 10) def test_get(self):