Skip to content

Commit

Permalink
Fix issue opentelemetry-instrumentation-asgi: do not set url.full att…
Browse files Browse the repository at this point in the history
…ribute for server spans (open-telemetry#2735)
  • Loading branch information
shijiadong2022 authored Aug 14, 2024
1 parent 9c327ea commit af9e841
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#2750](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2750))
- `opentelemetry-instrumentation-django` Fix regression - `http.target` re-added back to old semconv duration metrics
([#2746](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2746))
- `opentelemetry-instrumentation-asgi` do not set `url.full` attribute for server spans
([#2735](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2735))
- `opentelemetry-instrumentation-grpc` Fixes the issue with the gRPC instrumentation not working with the 1.63.0 and higher version of gRPC
([#2483](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2484))
- `opentelemetry-instrumentation-aws-lambda` Fixing w3c baggage support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ def collect_request_attributes(
result, path, path, query_string, sem_conv_opt_in_mode
)
if http_url:
_set_http_url(
result, remove_url_credentials(http_url), sem_conv_opt_in_mode
)

if _report_old(sem_conv_opt_in_mode):
_set_http_url(
result,
remove_url_credentials(http_url),
_HTTPStabilityMode.DEFAULT,
)
http_method = scope.get("method", "")
if http_method:
_set_http_method(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
SERVER_PORT,
)
from opentelemetry.semconv.attributes.url_attributes import (
URL_FULL,
URL_PATH,
URL_QUERY,
URL_SCHEME,
Expand Down Expand Up @@ -410,7 +409,6 @@ def validate_outputs(
SERVER_ADDRESS: "127.0.0.1",
NETWORK_PROTOCOL_VERSION: "1.0",
URL_PATH: "/",
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 @@ -447,7 +445,6 @@ def validate_outputs(
SERVER_ADDRESS: "127.0.0.1",
NETWORK_PROTOCOL_VERSION: "1.0",
URL_PATH: "/",
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 @@ -693,7 +690,6 @@ def update_expected_server(expected):
{
SERVER_ADDRESS: "0.0.0.0",
SERVER_PORT: 80,
URL_FULL: "http://0.0.0.0/",
}
)
return expected
Expand Down Expand Up @@ -721,7 +717,6 @@ def update_expected_server(expected):
SpanAttributes.HTTP_URL: "http://0.0.0.0/",
SERVER_ADDRESS: "0.0.0.0",
SERVER_PORT: 80,
URL_FULL: "http://0.0.0.0/",
}
)
return expected
Expand Down Expand Up @@ -1009,7 +1004,6 @@ def test_websocket_new_semconv(self):
SERVER_ADDRESS: self.scope["server"][0],
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
URL_PATH: self.scope["path"],
URL_FULL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
CLIENT_ADDRESS: self.scope["client"][0],
CLIENT_PORT: self.scope["client"][1],
HTTP_RESPONSE_STATUS_CODE: 200,
Expand Down Expand Up @@ -1095,7 +1089,6 @@ def test_websocket_both_semconv(self):
SERVER_ADDRESS: self.scope["server"][0],
NETWORK_PROTOCOL_VERSION: self.scope["http_version"],
URL_PATH: self.scope["path"],
URL_FULL: f'{self.scope["scheme"]}://{self.scope["server"][0]}{self.scope["path"]}',
CLIENT_ADDRESS: self.scope["client"][0],
CLIENT_PORT: self.scope["client"][1],
HTTP_RESPONSE_STATUS_CODE: 200,
Expand Down Expand Up @@ -1639,7 +1632,6 @@ def test_request_attributes_new_semconv(self):
SERVER_ADDRESS: "127.0.0.1",
URL_PATH: "/",
URL_QUERY: "foo=bar",
URL_FULL: "http://127.0.0.1/?foo=bar",
SERVER_PORT: 80,
URL_SCHEME: "http",
NETWORK_PROTOCOL_VERSION: "1.0",
Expand Down Expand Up @@ -1676,7 +1668,6 @@ def test_request_attributes_both_semconv(self):
SERVER_ADDRESS: "127.0.0.1",
URL_PATH: "/",
URL_QUERY: "foo=bar",
URL_FULL: "http://127.0.0.1/?foo=bar",
SERVER_PORT: 80,
URL_SCHEME: "http",
NETWORK_PROTOCOL_VERSION: "1.0",
Expand All @@ -1698,18 +1689,24 @@ def test_query_string_new_semconv(self):
self.scope,
_HTTPStabilityMode.HTTP,
)
self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar")
self.assertEqual(attrs[URL_SCHEME], "http")
self.assertEqual(attrs[SERVER_ADDRESS], "127.0.0.1")
self.assertEqual(attrs[URL_PATH], "/")
self.assertEqual(attrs[URL_QUERY], "foo=bar")

def test_query_string_both_semconv(self):
self.scope["query_string"] = b"foo=bar"
attrs = otel_asgi.collect_request_attributes(
self.scope,
_HTTPStabilityMode.HTTP_DUP,
)
self.assertEqual(attrs[URL_FULL], "http://127.0.0.1/?foo=bar")
self.assertEqual(
attrs[SpanAttributes.HTTP_URL], "http://127.0.0.1/?foo=bar"
)
self.assertEqual(attrs[URL_SCHEME], "http")
self.assertEqual(attrs[SERVER_ADDRESS], "127.0.0.1")
self.assertEqual(attrs[URL_PATH], "/")
self.assertEqual(attrs[URL_QUERY], "foo=bar")

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

0 comments on commit af9e841

Please sign in to comment.