3737 NumberDataPoint ,
3838)
3939from opentelemetry .sdk .resources import Resource
40+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
41+ HTTP_FLAVOR ,
42+ HTTP_HOST ,
43+ HTTP_METHOD ,
44+ HTTP_SCHEME ,
45+ HTTP_SERVER_NAME ,
46+ HTTP_STATUS_CODE ,
47+ HTTP_TARGET ,
48+ HTTP_URL ,
49+ HTTP_USER_AGENT ,
50+ )
51+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
52+ NET_HOST_NAME ,
53+ NET_HOST_PORT ,
54+ )
4055from opentelemetry .semconv .attributes .http_attributes import (
4156 HTTP_REQUEST_METHOD ,
4257 HTTP_RESPONSE_STATUS_CODE ,
5469 URL_QUERY ,
5570 URL_SCHEME ,
5671)
57- from opentelemetry .semconv .trace import SpanAttributes
72+ from opentelemetry .semconv .attributes .user_agent_attributes import (
73+ USER_AGENT_ORIGINAL ,
74+ )
5875from opentelemetry .test .test_base import TestBase
5976from opentelemetry .test .wsgitestutil import WsgiTestBase
6077from opentelemetry .trace import StatusCode
@@ -245,14 +262,14 @@ def validate_response(
245262 self .assertEqual (span_list [0 ].kind , trace_api .SpanKind .SERVER )
246263 expected_attributes = {}
247264 expected_attributes_old = {
248- SpanAttributes . HTTP_SERVER_NAME : "127.0.0.1" ,
249- SpanAttributes . HTTP_SCHEME : "http" ,
250- SpanAttributes . NET_HOST_PORT : 80 ,
251- SpanAttributes . HTTP_HOST : "127.0.0.1" ,
252- SpanAttributes . HTTP_FLAVOR : "1.0" ,
253- SpanAttributes . HTTP_URL : "http://127.0.0.1/" ,
254- SpanAttributes . HTTP_STATUS_CODE : 200 ,
255- SpanAttributes . NET_HOST_NAME : "127.0.0.1" ,
265+ HTTP_SERVER_NAME : "127.0.0.1" ,
266+ HTTP_SCHEME : "http" ,
267+ NET_HOST_PORT : 80 ,
268+ HTTP_HOST : "127.0.0.1" ,
269+ HTTP_FLAVOR : "1.0" ,
270+ HTTP_URL : "http://127.0.0.1/" ,
271+ HTTP_STATUS_CODE : 200 ,
272+ NET_HOST_NAME : "127.0.0.1" ,
256273 }
257274 expected_attributes_new = {
258275 SERVER_PORT : 80 ,
@@ -269,7 +286,7 @@ def validate_response(
269286 expected_attributes .update (span_attributes or {})
270287 if http_method is not None :
271288 if old_sem_conv :
272- expected_attributes [SpanAttributes . HTTP_METHOD ] = http_method
289+ expected_attributes [HTTP_METHOD ] = http_method
273290 if new_sem_conv :
274291 expected_attributes [HTTP_REQUEST_METHOD ] = http_method
275292 self .assertEqual (span_list [0 ].attributes , expected_attributes )
@@ -523,14 +540,14 @@ def test_request_attributes(self):
523540 self .assertDictEqual (
524541 attrs ,
525542 {
526- SpanAttributes . HTTP_METHOD : "GET" ,
527- SpanAttributes . HTTP_HOST : "127.0.0.1" ,
528- SpanAttributes . HTTP_URL : "http://127.0.0.1/?foo=bar" ,
529- SpanAttributes . NET_HOST_PORT : 80 ,
530- SpanAttributes . HTTP_SCHEME : "http" ,
531- SpanAttributes . HTTP_SERVER_NAME : "127.0.0.1" ,
532- SpanAttributes . HTTP_FLAVOR : "1.0" ,
533- SpanAttributes . NET_HOST_NAME : "127.0.0.1" ,
543+ HTTP_METHOD : "GET" ,
544+ HTTP_HOST : "127.0.0.1" ,
545+ HTTP_URL : "http://127.0.0.1/?foo=bar" ,
546+ NET_HOST_PORT : 80 ,
547+ HTTP_SCHEME : "http" ,
548+ HTTP_SERVER_NAME : "127.0.0.1" ,
549+ HTTP_FLAVOR : "1.0" ,
550+ NET_HOST_NAME : "127.0.0.1" ,
534551 },
535552 )
536553
@@ -565,10 +582,10 @@ def validate_url(
565582 ):
566583 parts = urlsplit (expected_url )
567584 expected_old = {
568- SpanAttributes . HTTP_SCHEME : parts .scheme ,
569- SpanAttributes . NET_HOST_PORT : parts .port
585+ HTTP_SCHEME : parts .scheme ,
586+ NET_HOST_PORT : parts .port
570587 or (80 if parts .scheme == "http" else 443 ),
571- SpanAttributes . HTTP_SERVER_NAME : parts .hostname , # Not true in the general case, but for all tests.
588+ HTTP_SERVER_NAME : parts .hostname , # Not true in the general case, but for all tests.
572589 }
573590 expected_new = {
574591 SERVER_PORT : parts .port or (80 if parts .scheme == "http" else 443 ),
@@ -578,13 +595,13 @@ def validate_url(
578595 }
579596 if old_semconv :
580597 if raw :
581- expected_old [SpanAttributes . HTTP_TARGET ] = expected_url .split (
598+ expected_old [HTTP_TARGET ] = expected_url .split (
582599 parts .netloc , 1
583600 )[1 ]
584601 else :
585- expected_old [SpanAttributes . HTTP_URL ] = expected_url
602+ expected_old [HTTP_URL ] = expected_url
586603 if has_host :
587- expected_old [SpanAttributes . HTTP_HOST ] = parts .hostname
604+ expected_old [HTTP_HOST ] = parts .hostname
588605 if new_semconv :
589606 if raw :
590607 expected_new [URL_PATH ] = expected_url .split (parts .path , 1 )[1 ]
@@ -713,9 +730,9 @@ def test_request_attributes_with_conflicting_nonstandard_port(self):
713730 ":8080" # Note that we do not correct SERVER_PORT
714731 )
715732 expected = {
716- SpanAttributes . HTTP_HOST : "127.0.0.1:8080" ,
717- SpanAttributes . HTTP_URL : "http://127.0.0.1:8080/" ,
718- SpanAttributes . NET_HOST_PORT : 80 ,
733+ HTTP_HOST : "127.0.0.1:8080" ,
734+ HTTP_URL : "http://127.0.0.1:8080/" ,
735+ NET_HOST_PORT : 80 ,
719736 }
720737 self .assertGreaterEqual (
721738 otel_wsgi .collect_request_attributes (self .environ ).items (),
@@ -729,9 +746,7 @@ def test_request_attributes_with_faux_scheme_relative_raw_uri(self):
729746 def test_request_attributes_pathless (self ):
730747 self .environ ["RAW_URI" ] = ""
731748 self .assertIsNone (
732- otel_wsgi .collect_request_attributes (self .environ ).get (
733- SpanAttributes .HTTP_TARGET
734- )
749+ otel_wsgi .collect_request_attributes (self .environ ).get (HTTP_TARGET )
735750 )
736751
737752 def test_request_attributes_with_full_request_uri (self ):
@@ -741,8 +756,8 @@ def test_request_attributes_with_full_request_uri(self):
741756 "http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing" # Might happen in a CONNECT request
742757 )
743758 expected_old = {
744- SpanAttributes . HTTP_HOST : "127.0.0.1:8080" ,
745- SpanAttributes . HTTP_TARGET : "http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing" ,
759+ HTTP_HOST : "127.0.0.1:8080" ,
760+ HTTP_TARGET : "http://docs.python.org:80/3/library/urllib.parse.html?highlight=params#url-parsing" ,
746761 }
747762 expected_new = {
748763 URL_PATH : "/3/library/urllib.parse.html" ,
@@ -762,8 +777,8 @@ def test_request_attributes_with_full_request_uri(self):
762777
763778 def test_http_user_agent_attribute (self ):
764779 self .environ ["HTTP_USER_AGENT" ] = "test-useragent"
765- expected = {SpanAttributes . HTTP_USER_AGENT : "test-useragent" }
766- expected_new = {SpanAttributes . USER_AGENT_ORIGINAL : "test-useragent" }
780+ expected = {HTTP_USER_AGENT : "test-useragent" }
781+ expected_new = {USER_AGENT_ORIGINAL : "test-useragent" }
767782 self .assertGreaterEqual (
768783 otel_wsgi .collect_request_attributes (self .environ ).items (),
769784 expected .items (),
@@ -784,10 +799,8 @@ def test_response_attributes(self):
784799 {},
785800 sem_conv_opt_in_mode = _StabilityMode .HTTP ,
786801 )
787- expected = (mock .call (SpanAttributes .HTTP_STATUS_CODE , 404 ),)
788- expected_new = (
789- mock .call (SpanAttributes .HTTP_RESPONSE_STATUS_CODE , 404 ),
790- )
802+ expected = (mock .call (HTTP_STATUS_CODE , 404 ),)
803+ expected_new = (mock .call (HTTP_RESPONSE_STATUS_CODE , 404 ),)
791804 self .assertEqual (self .span .set_attribute .call_count , 2 )
792805 self .span .set_attribute .assert_has_calls (expected , any_order = True )
793806 self .span .set_attribute .assert_has_calls (expected_new , any_order = True )
@@ -803,14 +816,14 @@ def test_response_attributes_noop(self):
803816
804817 self .assertEqual (mock_span .set_attribute .call_count , 0 )
805818 self .assertEqual (mock_span .is_recording .call_count , 2 )
806- self .assertEqual (attrs [SpanAttributes . HTTP_STATUS_CODE ], 404 )
819+ self .assertEqual (attrs [HTTP_STATUS_CODE ], 404 )
807820
808821 def test_credential_removal (self ):
809822 self .environ ["HTTP_HOST" ] = "username:password@mock"
810823 self .environ ["PATH_INFO" ] = "/status/200"
811824 expected = {
812- SpanAttributes . HTTP_URL : "http://mock/status/200" ,
813- SpanAttributes . NET_HOST_PORT : 80 ,
825+ HTTP_URL : "http://mock/status/200" ,
826+ NET_HOST_PORT : 80 ,
814827 }
815828 self .assertGreaterEqual (
816829 otel_wsgi .collect_request_attributes (self .environ ).items (),
0 commit comments