Repository: open-telemetry/opentelemetry-python-contrib

Issue:
Rename "host.port" attribute to "net.host.port"
According to Semantic Conventions https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/metrics/semantic_conventions/http-metrics.md
attribute "net.host.port" should be used instead of "host.port"


Discussion:

Resolving patch:
diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py
@@ -75,7 +75,7 @@ def collect_request_attributes(scope):
         "component": scope["type"],
         "http.scheme": scope.get("scheme"),
         "http.host": server_host,
-        "host.port": port,
+        "net.host.port": port,
         "http.flavor": scope.get("http_version"),
         "http.target": scope.get("path"),
         "http.url": http_url,
diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
--- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
+++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py
@@ -112,7 +112,7 @@ def collect_request_attributes(environ):
 
     host_port = environ.get("SERVER_PORT")
     if host_port is not None:
-        result.update({"host.port": int(host_port)})
+        result.update({"net.host.port": int(host_port)})
 
     setifnotnone(result, "http.host", environ.get("HTTP_HOST"))
     target = environ.get("RAW_URI")


Test patch:
diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
--- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
+++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py
@@ -137,7 +137,7 @@ def validate_outputs(self, outputs, error=None, modifiers=None):
                     "component": "http",
                     "http.method": "GET",
                     "http.scheme": "http",
-                    "host.port": 80,
+                    "net.host.port": 80,
                     "http.host": "127.0.0.1",
                     "http.flavor": "1.0",
                     "http.target": "/",
@@ -218,7 +218,7 @@ def update_expected_server(expected):
             expected[3]["attributes"].update(
                 {
                     "http.host": "0.0.0.0",
-                    "host.port": 80,
+                    "net.host.port": 80,
                     "http.url": "http://0.0.0.0/",
                 }
             )
@@ -326,7 +326,7 @@ def test_request_attributes(self):
                 "http.host": "127.0.0.1",
                 "http.target": "/",
                 "http.url": "http://127.0.0.1/?foo=bar",
-                "host.port": 80,
+                "net.host.port": 80,
                 "http.scheme": "http",
                 "http.server_name": "test",
                 "http.flavor": "1.0",
diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py
--- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py
+++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py
@@ -99,7 +99,7 @@ def _test_method(self, method):
                 "http.method": method,
                 "http.server_name": "falconframework.org",
                 "http.scheme": "http",
-                "host.port": 80,
+                "net.host.port": 80,
                 "http.host": "falconframework.org",
                 "http.target": "/",
                 "net.peer.ip": "127.0.0.1",
@@ -126,7 +126,7 @@ def test_404(self):
                 "http.method": "GET",
                 "http.server_name": "falconframework.org",
                 "http.scheme": "http",
-                "host.port": 80,
+                "net.host.port": 80,
                 "http.host": "falconframework.org",
                 "http.target": "/",
                 "net.peer.ip": "127.0.0.1",
@@ -159,7 +159,7 @@ def test_500(self):
                 "http.method": "GET",
                 "http.server_name": "falconframework.org",
                 "http.scheme": "http",
-                "host.port": 80,
+                "net.host.port": 80,
                 "http.host": "falconframework.org",
                 "http.target": "/",
                 "net.peer.ip": "127.0.0.1",
diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py
--- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py
+++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py
@@ -32,7 +32,7 @@ def expected_attributes(override_attributes):
         "http.method": "GET",
         "http.server_name": "localhost",
         "http.scheme": "http",
-        "host.port": 80,
+        "net.host.port": 80,
         "http.host": "localhost",
         "http.target": "/",
         "http.flavor": "1.1",
diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py
--- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py
+++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py
@@ -32,7 +32,7 @@ def expected_attributes(override_attributes):
         "http.method": "GET",
         "http.server_name": "localhost",
         "http.scheme": "http",
-        "host.port": 80,
+        "net.host.port": 80,
         "http.host": "localhost",
         "http.target": "/",
         "http.flavor": "1.1",
diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py
--- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py
+++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py
@@ -109,7 +109,7 @@ def validate_response(
             "component": "http",
             "http.server_name": "127.0.0.1",
             "http.scheme": "http",
-            "host.port": 80,
+            "net.host.port": 80,
             "http.host": "127.0.0.1",
             "http.flavor": "1.0",
             "http.url": "http://127.0.0.1/",
@@ -219,7 +219,7 @@ def test_request_attributes(self):
                 "http.method": "GET",
                 "http.host": "127.0.0.1",
                 "http.url": "http://127.0.0.1/?foo=bar",
-                "host.port": 80,
+                "net.host.port": 80,
                 "http.scheme": "http",
                 "http.server_name": "127.0.0.1",
                 "http.flavor": "1.0",
@@ -230,7 +230,8 @@ def validate_url(self, expected_url, raw=False, has_host=True):
         parts = urlsplit(expected_url)
         expected = {
             "http.scheme": parts.scheme,
-            "host.port": parts.port or (80 if parts.scheme == "http" else 443),
+            "net.host.port": parts.port
+            or (80 if parts.scheme == "http" else 443),
             "http.server_name": parts.hostname,  # Not true in the general case, but for all tests.
         }
         if raw:
@@ -296,7 +297,7 @@ def test_request_attributes_with_conflicting_nonstandard_port(self):
         expected = {
             "http.host": "127.0.0.1:8080",
             "http.url": "http://127.0.0.1:8080/",
-            "host.port": 80,
+            "net.host.port": 80,
         }
         self.assertGreaterEqual(
             otel_wsgi.collect_request_attributes(self.environ).items(),