Skip to content

Commit af9e841

Browse files
Fix issue opentelemetry-instrumentation-asgi: do not set url.full attribute for server spans (#2735)
1 parent 9c327ea commit af9e841

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
([#2750](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2750))
2727
- `opentelemetry-instrumentation-django` Fix regression - `http.target` re-added back to old semconv duration metrics
2828
([#2746](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2746))
29+
- `opentelemetry-instrumentation-asgi` do not set `url.full` attribute for server spans
30+
([#2735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2735))
2931
- `opentelemetry-instrumentation-grpc` Fixes the issue with the gRPC instrumentation not working with the 1.63.0 and higher version of gRPC
3032
([#2483](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2484))
3133
- `opentelemetry-instrumentation-aws-lambda` Fixing w3c baggage support

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,12 @@ def collect_request_attributes(
354354
result, path, path, query_string, sem_conv_opt_in_mode
355355
)
356356
if http_url:
357-
_set_http_url(
358-
result, remove_url_credentials(http_url), sem_conv_opt_in_mode
359-
)
360-
357+
if _report_old(sem_conv_opt_in_mode):
358+
_set_http_url(
359+
result,
360+
remove_url_credentials(http_url),
361+
_HTTPStabilityMode.DEFAULT,
362+
)
361363
http_method = scope.get("method", "")
362364
if http_method:
363365
_set_http_method(

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
SERVER_PORT,
5959
)
6060
from opentelemetry.semconv.attributes.url_attributes import (
61-
URL_FULL,
6261
URL_PATH,
6362
URL_QUERY,
6463
URL_SCHEME,
@@ -410,7 +409,6 @@ def validate_outputs(
410409
SERVER_ADDRESS: "127.0.0.1",
411410
NETWORK_PROTOCOL_VERSION: "1.0",
412411
URL_PATH: "/",
413-
URL_FULL: "http://127.0.0.1/",
414412
CLIENT_ADDRESS: "127.0.0.1",
415413
CLIENT_PORT: 32767,
416414
HTTP_RESPONSE_STATUS_CODE: 200,
@@ -447,7 +445,6 @@ def validate_outputs(
447445
SERVER_ADDRESS: "127.0.0.1",
448446
NETWORK_PROTOCOL_VERSION: "1.0",
449447
URL_PATH: "/",
450-
URL_FULL: "http://127.0.0.1/",
451448
CLIENT_ADDRESS: "127.0.0.1",
452449
CLIENT_PORT: 32767,
453450
HTTP_RESPONSE_STATUS_CODE: 200,
@@ -693,7 +690,6 @@ def update_expected_server(expected):
693690
{
694691
SERVER_ADDRESS: "0.0.0.0",
695692
SERVER_PORT: 80,
696-
URL_FULL: "http://0.0.0.0/",
697693
}
698694
)
699695
return expected
@@ -721,7 +717,6 @@ def update_expected_server(expected):
721717
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
722718
SERVER_ADDRESS: "0.0.0.0",
723719
SERVER_PORT: 80,
724-
URL_FULL: "http://0.0.0.0/",
725720
}
726721
)
727722
return expected
@@ -1009,7 +1004,6 @@ def test_websocket_new_semconv(self):
10091004
SERVER_ADDRESS: self.scope["server"][0],
10101005
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
10111006
URL_PATH: self.scope["path"],
1012-
URL_FULL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
10131007
CLIENT_ADDRESS: self.scope["client"][0],
10141008
CLIENT_PORT: self.scope["client"][1],
10151009
HTTP_RESPONSE_STATUS_CODE: 200,
@@ -1095,7 +1089,6 @@ def test_websocket_both_semconv(self):
10951089
SERVER_ADDRESS: self.scope["server"][0],
10961090
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
10971091
URL_PATH: self.scope["path"],
1098-
URL_FULL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
10991092
CLIENT_ADDRESS: self.scope["client"][0],
11001093
CLIENT_PORT: self.scope["client"][1],
11011094
HTTP_RESPONSE_STATUS_CODE: 200,
@@ -1639,7 +1632,6 @@ def test_request_attributes_new_semconv(self):
16391632
SERVER_ADDRESS: "127.0.0.1",
16401633
URL_PATH: "/",
16411634
URL_QUERY: "foo=bar",
1642-
URL_FULL: "http://127.0.0.1/?foo=bar",
16431635
SERVER_PORT: 80,
16441636
URL_SCHEME: "http",
16451637
NETWORK_PROTOCOL_VERSION: "1.0",
@@ -1676,7 +1668,6 @@ def test_request_attributes_both_semconv(self):
16761668
SERVER_ADDRESS: "127.0.0.1",
16771669
URL_PATH: "/",
16781670
URL_QUERY: "foo=bar",
1679-
URL_FULL: "http://127.0.0.1/?foo=bar",
16801671
SERVER_PORT: 80,
16811672
URL_SCHEME: "http",
16821673
NETWORK_PROTOCOL_VERSION: "1.0",
@@ -1698,18 +1689,24 @@ def test_query_string_new_semconv(self):
16981689
self.scope,
16991690
_HTTPStabilityMode.HTTP,
17001691
)
1701-
self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar")
1692+
self.assertEqual(attrs[URL_SCHEME], "http")
1693+
self.assertEqual(attrs[SERVER_ADDRESS], "127.0.0.1")
1694+
self.assertEqual(attrs[URL_PATH], "/")
1695+
self.assertEqual(attrs[URL_QUERY], "foo=bar")
17021696

17031697
def test_query_string_both_semconv(self):
17041698
self.scope["query_string"] = b"foo=bar"
17051699
attrs = otel_asgi.collect_request_attributes(
17061700
self.scope,
17071701
_HTTPStabilityMode.HTTP_DUP,
17081702
)
1709-
self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar")
17101703
self.assertEqual(
17111704
attrs[SpanAttributes.HTTP_URL], "http://127.0.0.1/?foo=bar"
17121705
)
1706+
self.assertEqual(attrs[URL_SCHEME], "http")
1707+
self.assertEqual(attrs[SERVER_ADDRESS], "127.0.0.1")
1708+
self.assertEqual(attrs[URL_PATH], "/")
1709+
self.assertEqual(attrs[URL_QUERY], "foo=bar")
17131710

17141711
def test_query_string_percent_bytes(self):
17151712
self.scope["query_string"] = b"foo%3Dbar"

0 commit comments

Comments
 (0)