Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def client_response_hook(span: Span, scope: Scope, message: dict[str, Any]):
from opentelemetry.instrumentation.utils import _start_internal_or_server_span
from opentelemetry.metrics import get_meter
from opentelemetry.propagators.textmap import Getter, Setter
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_SERVER_NAME,
)
from opentelemetry.semconv._incubating.attributes.user_agent_attributes import (
USER_AGENT_SYNTHETIC_TYPE,
)
Expand Down Expand Up @@ -397,9 +400,7 @@ def collect_request_attributes(
http_host_value_list = asgi_getter.get(scope, "host")
if http_host_value_list:
if _report_old(sem_conv_opt_in_mode):
result[SpanAttributes.HTTP_SERVER_NAME] = ",".join(
http_host_value_list
)
result[HTTP_SERVER_NAME] = ",".join(http_host_value_list)
http_user_agent = asgi_getter.get(scope, "user-agent")
if http_user_agent:
user_agent_raw = http_user_agent[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
HistogramDataPoint,
NumberDataPoint,
)
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_SERVER_NAME,
)
from opentelemetry.semconv._incubating.attributes.user_agent_attributes import (
USER_AGENT_SYNTHETIC_TYPE,
)
Expand All @@ -61,6 +64,7 @@
SERVER_PORT,
)
from opentelemetry.semconv.attributes.url_attributes import (
URL_FULL,
URL_PATH,
URL_QUERY,
URL_SCHEME,
Expand Down Expand Up @@ -368,7 +372,7 @@ def validate_outputs(
"name": "GET / http send",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {
SpanAttributes.HTTP_STATUS_CODE: 200,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task is to substitute the use of SpanAttributes with other modules inside opentelemetry.semconv, not to change what is asserted here. If we don't have a replacement with the same value then they should stay untouched

HTTP_RESPONSE_STATUS_CODE: 200,
"asgi.event.type": "http.response.start",
},
},
Expand All @@ -381,16 +385,16 @@ def validate_outputs(
"name": "GET /",
"kind": trace_api.SpanKind.SERVER,
"attributes": {
SpanAttributes.HTTP_METHOD: "GET",
HTTP_REQUEST_METHOD: "GET",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "127.0.0.1",
SERVER_PORT: 80,
SERVER_ADDRESS: "127.0.0.1",
SpanAttributes.HTTP_FLAVOR: "1.0",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://127.0.0.1/",
SpanAttributes.NET_PEER_IP: "127.0.0.1",
SpanAttributes.NET_PEER_PORT: 32767,
SpanAttributes.HTTP_STATUS_CODE: 200,
URL_FULL: "http://127.0.0.1/",
CLIENT_ADDRESS: "127.0.0.1",
CLIENT_PORT: 32767,
HTTP_RESPONSE_STATUS_CODE: 200,
},
},
]
Expand Down Expand Up @@ -439,7 +443,6 @@ def validate_outputs(
"name": "GET / http send",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_RESPONSE_STATUS_CODE: 200,
"asgi.event.type": "http.response.start",
},
Expand All @@ -462,16 +465,10 @@ def validate_outputs(
CLIENT_ADDRESS: "127.0.0.1",
CLIENT_PORT: 32767,
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.NET_HOST_PORT: 80,
SpanAttributes.HTTP_HOST: "127.0.0.1",
SpanAttributes.HTTP_FLAVOR: "1.0",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://127.0.0.1/",
SpanAttributes.NET_PEER_IP: "127.0.0.1",
SpanAttributes.NET_PEER_PORT: 32767,
SpanAttributes.HTTP_STATUS_CODE: 200,
URL_FULL: "http://127.0.0.1/",
},
},
]
Expand Down Expand Up @@ -713,7 +710,7 @@ def update_expected_server(expected):
expected[3]["attributes"].update(
{
SpanAttributes.HTTP_HOST: "0.0.0.0",
SpanAttributes.NET_HOST_PORT: 80,
SERVER_PORT: 80,
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
}
)
Expand Down Expand Up @@ -757,10 +754,9 @@ def update_expected_server(expected):
expected[3]["attributes"].update(
{
SpanAttributes.HTTP_HOST: "0.0.0.0",
SpanAttributes.NET_HOST_PORT: 80,
SERVER_PORT: 80,
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
SERVER_ADDRESS: "0.0.0.0",
SERVER_PORT: 80,
}
)
return expected
Expand All @@ -784,7 +780,7 @@ async def test_host_header(self):
def update_expected_server(expected):
expected[3]["attributes"].update(
{
SpanAttributes.HTTP_SERVER_NAME: hostname.decode("utf8"),
HTTP_SERVER_NAME: hostname.decode("utf8"),
SpanAttributes.HTTP_URL: f"http://{hostname.decode('utf8')}/",
}
)
Expand Down Expand Up @@ -1094,15 +1090,15 @@ async def test_websocket(self):
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {
"asgi.event.type": "websocket.receive",
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_RESPONSE_STATUS_CODE: 200,
},
},
{
"name": "GET / websocket send",
"kind": trace_api.SpanKind.INTERNAL,
"attributes": {
"asgi.event.type": "websocket.send",
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_RESPONSE_STATUS_CODE: 200,
},
},
{
Expand All @@ -1122,7 +1118,7 @@ async def test_websocket(self):
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_METHOD: self.scope["method"],
},
},
Expand Down Expand Up @@ -1242,7 +1238,6 @@ async def test_websocket_both_semconv(self):
"attributes": {
"asgi.event.type": "websocket.receive",
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_STATUS_CODE: 200,
},
},
{
Expand All @@ -1251,7 +1246,6 @@ async def test_websocket_both_semconv(self):
"attributes": {
"asgi.event.type": "websocket.send",
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_STATUS_CODE: 200,
},
},
{
Expand All @@ -1271,7 +1265,7 @@ async def test_websocket_both_semconv(self):
SpanAttributes.HTTP_URL: f"{self.scope['scheme']}://{self.scope['server'][0]}{self.scope['path']}",
SpanAttributes.NET_PEER_IP: self.scope["client"][0],
SpanAttributes.NET_PEER_PORT: self.scope["client"][1],
SpanAttributes.HTTP_STATUS_CODE: 200,
HTTP_RESPONSE_STATUS_CODE: 200,
SpanAttributes.HTTP_METHOD: self.scope["method"],
URL_SCHEME: self.scope["scheme"],
SERVER_ADDRESS: self.scope["server"][0],
Expand All @@ -1280,7 +1274,6 @@ async def test_websocket_both_semconv(self):
URL_PATH: self.scope["path"],
CLIENT_ADDRESS: self.scope["client"][0],
CLIENT_PORT: self.scope["client"][1],
HTTP_RESPONSE_STATUS_CODE: 200,
HTTP_REQUEST_METHOD: self.scope["method"],
},
},
Expand Down Expand Up @@ -1873,16 +1866,16 @@ def test_request_attributes(self):
self.assertDictEqual(
attrs,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_HOST: "127.0.0.1",
HTTP_REQUEST_METHOD: "GET",
SERVER_ADDRESS: "127.0.0.1",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://test/?foo=bar",
SpanAttributes.NET_HOST_PORT: 80,
SERVER_PORT: 80,
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.HTTP_SERVER_NAME: "test",
SpanAttributes.HTTP_FLAVOR: "1.0",
SpanAttributes.NET_PEER_IP: "127.0.0.1",
SpanAttributes.NET_PEER_PORT: 32767,
CLIENT_ADDRESS: "127.0.0.1",
CLIENT_PORT: 32767,
},
)

Expand Down Expand Up @@ -1926,25 +1919,20 @@ def test_request_attributes_both_semconv(self):
self.assertDictEqual(
attrs,
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_HOST: "127.0.0.1",
HTTP_REQUEST_METHOD: "GET",
SERVER_ADDRESS: "127.0.0.1",
SpanAttributes.HTTP_TARGET: "/",
SpanAttributes.HTTP_URL: "http://test/?foo=bar",
SpanAttributes.NET_HOST_PORT: 80,
SERVER_PORT: 80,
SpanAttributes.HTTP_SCHEME: "http",
SpanAttributes.HTTP_SERVER_NAME: "test",
SpanAttributes.HTTP_FLAVOR: "1.0",
SpanAttributes.NET_PEER_IP: "127.0.0.1",
SpanAttributes.NET_PEER_PORT: 32767,
HTTP_REQUEST_METHOD: "GET",
CLIENT_ADDRESS: "127.0.0.1",
CLIENT_PORT: 32767,
URL_PATH: "/",
URL_QUERY: "foo=bar",
SERVER_ADDRESS: "127.0.0.1",
SERVER_PORT: 80,
URL_SCHEME: "http",
NETWORK_PROTOCOL_VERSION: "1.0",
CLIENT_ADDRESS: "127.0.0.1",
CLIENT_PORT: 32767,
},
)

Expand Down