diff --git a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py index 6ed83338a0..a368ed7a97 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py @@ -119,6 +119,9 @@ def response_hook(span: Span, request: Request, response: HTTPResponse): ) from opentelemetry.metrics import Histogram, Meter, get_meter from opentelemetry.propagate import inject +from opentelemetry.semconv._incubating.attributes.http_attributes import ( + HTTP_URL, +) from opentelemetry.semconv._incubating.metrics.http_metrics import ( HTTP_CLIENT_REQUEST_BODY_SIZE, HTTP_CLIENT_RESPONSE_BODY_SIZE, @@ -130,7 +133,6 @@ def response_hook(span: Span, request: Request, response: HTTPResponse): from opentelemetry.semconv.metrics.http_metrics import ( HTTP_CLIENT_REQUEST_DURATION, ) -from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace import Span, SpanKind, Tracer, get_tracer from opentelemetry.util.http import ( ExcludeList, @@ -325,7 +327,7 @@ def _instrumented_open_call( sem_conv_opt_in_mode=_StabilityMode.HTTP, ) - duration_attrs_old[SpanAttributes.HTTP_URL] = url + duration_attrs_old[HTTP_URL] = url _record_histograms( histograms, diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py index 219a484948..c9f45e141e 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py @@ -38,13 +38,17 @@ ) from opentelemetry.propagate import get_global_textmap, set_global_textmap from opentelemetry.sdk import resources +from opentelemetry.semconv._incubating.attributes.http_attributes import ( + HTTP_METHOD, + HTTP_STATUS_CODE, + HTTP_URL, +) from opentelemetry.semconv.attributes.error_attributes import ERROR_TYPE from opentelemetry.semconv.attributes.http_attributes import ( HTTP_REQUEST_METHOD, HTTP_RESPONSE_STATUS_CODE, ) from opentelemetry.semconv.attributes.url_attributes import URL_FULL -from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.test.mock_textmap import MockTextMapPropagator from opentelemetry.test.test_base import TestBase from opentelemetry.trace import StatusCode @@ -150,9 +154,9 @@ def test_basic(self): self.assertEqual( span.attributes, { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: self.URL, - SpanAttributes.HTTP_STATUS_CODE: 200, + HTTP_METHOD: "GET", + HTTP_URL: self.URL, + HTTP_STATUS_CODE: 200, }, ) @@ -198,9 +202,9 @@ def test_basic_both_semconv(self): self.assertEqual( span.attributes, { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: self.URL, - SpanAttributes.HTTP_STATUS_CODE: 200, + HTTP_METHOD: "GET", + HTTP_URL: self.URL, + HTTP_STATUS_CODE: 200, HTTP_REQUEST_METHOD: "GET", URL_FULL: self.URL, HTTP_RESPONSE_STATUS_CODE: 200, @@ -260,9 +264,7 @@ def test_not_foundbasic(self): span = self.assert_span() - self.assertEqual( - span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404 - ) + self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404) self.assertIs( span.status.status_code, @@ -310,9 +312,7 @@ def test_not_foundbasic_both_semconv(self): span = self.assert_span() - self.assertEqual( - span.attributes.get(SpanAttributes.HTTP_STATUS_CODE), 404 - ) + self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404) self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404) self.assertIs( @@ -337,8 +337,8 @@ def test_response_code_none(self): self.assertEqual( span.attributes, { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: self.URL, + HTTP_METHOD: "GET", + HTTP_URL: self.URL, }, ) @@ -455,9 +455,9 @@ def test_requests_exception_with_response(self, *_, **__): self.assertEqual( dict(span.attributes), { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: "http://mock/status/500", - SpanAttributes.HTTP_STATUS_CODE: 500, + HTTP_METHOD: "GET", + HTTP_URL: "http://mock/status/500", + HTTP_STATUS_CODE: 500, }, ) self.assertEqual(span.status.status_code, StatusCode.ERROR) @@ -486,9 +486,9 @@ def test_requests_exception_with_response_both_semconv(self, *_, **__): self.assertEqual( dict(span.attributes), { - SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: "http://mock/status/500", - SpanAttributes.HTTP_STATUS_CODE: 500, + HTTP_METHOD: "GET", + HTTP_URL: "http://mock/status/500", + HTTP_STATUS_CODE: 500, HTTP_REQUEST_METHOD: "GET", URL_FULL: "http://mock/status/500", HTTP_RESPONSE_STATUS_CODE: 500, @@ -520,7 +520,7 @@ def test_remove_sensitive_params(self): span = self.assert_span() self.assertEqual( - span.attributes[SpanAttributes.HTTP_URL], + span.attributes[HTTP_URL], "http://REDACTED:REDACTED@mock/status/200", )