4040 NumberDataPoint ,
4141)
4242from opentelemetry .sdk .resources import Resource
43+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
44+ HTTP_FLAVOR ,
45+ HTTP_HOST ,
46+ HTTP_METHOD ,
47+ HTTP_REQUEST_METHOD ,
48+ HTTP_RESPONSE_STATUS_CODE ,
49+ HTTP_ROUTE ,
50+ HTTP_SCHEME ,
51+ HTTP_SERVER_NAME ,
52+ HTTP_STATUS_CODE ,
53+ HTTP_TARGET ,
54+ )
55+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
56+ NET_HOST_NAME ,
57+ NET_HOST_PORT ,
58+ )
59+ from opentelemetry .semconv ._incubating .attributes .network_attributes import (
60+ NETWORK_PROTOCOL_VERSION ,
61+ )
62+ from opentelemetry .semconv ._incubating .attributes .server_attributes import (
63+ SERVER_ADDRESS ,
64+ SERVER_PORT ,
65+ )
66+ from opentelemetry .semconv ._incubating .attributes .url_attributes import (
67+ URL_PATH ,
68+ URL_SCHEME ,
69+ )
4370from opentelemetry .semconv .attributes .error_attributes import ERROR_TYPE
44- from opentelemetry .semconv .trace import SpanAttributes
4571from opentelemetry .test .wsgitestutil import WsgiTestBase
4672from opentelemetry .util .http import (
4773 OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ,
5783
5884def expected_attributes (override_attributes ):
5985 default_attributes = {
60- SpanAttributes . HTTP_METHOD : "GET" ,
61- SpanAttributes . HTTP_SERVER_NAME : "localhost" ,
62- SpanAttributes . HTTP_SCHEME : "http" ,
63- SpanAttributes . NET_HOST_PORT : 80 ,
64- SpanAttributes . NET_HOST_NAME : "localhost" ,
65- SpanAttributes . HTTP_HOST : "localhost" ,
66- SpanAttributes . HTTP_TARGET : "/" ,
67- SpanAttributes . HTTP_FLAVOR : "1.1" ,
68- SpanAttributes . HTTP_STATUS_CODE : 200 ,
86+ HTTP_METHOD : "GET" ,
87+ HTTP_SERVER_NAME : "localhost" ,
88+ HTTP_SCHEME : "http" ,
89+ NET_HOST_PORT : 80 ,
90+ NET_HOST_NAME : "localhost" ,
91+ HTTP_HOST : "localhost" ,
92+ HTTP_TARGET : "/" ,
93+ HTTP_FLAVOR : "1.1" ,
94+ HTTP_STATUS_CODE : 200 ,
6995 }
7096 for key , val in override_attributes .items ():
7197 default_attributes [key ] = val
@@ -74,12 +100,12 @@ def expected_attributes(override_attributes):
74100
75101def expected_attributes_new (override_attributes ):
76102 default_attributes = {
77- SpanAttributes . HTTP_REQUEST_METHOD : "GET" ,
78- SpanAttributes . SERVER_PORT : 80 ,
79- SpanAttributes . SERVER_ADDRESS : "localhost" ,
80- SpanAttributes . URL_PATH : "/hello/123" ,
81- SpanAttributes . NETWORK_PROTOCOL_VERSION : "1.1" ,
82- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 200 ,
103+ HTTP_REQUEST_METHOD : "GET" ,
104+ SERVER_PORT : 80 ,
105+ SERVER_ADDRESS : "localhost" ,
106+ URL_PATH : "/hello/123" ,
107+ NETWORK_PROTOCOL_VERSION : "1.1" ,
108+ HTTP_RESPONSE_STATUS_CODE : 200 ,
83109 }
84110 for key , val in override_attributes .items ():
85111 default_attributes [key ] = val
@@ -220,8 +246,8 @@ def assert_environ():
220246 def test_simple (self ):
221247 expected_attrs = expected_attributes (
222248 {
223- SpanAttributes . HTTP_TARGET : "/hello/123" ,
224- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
249+ HTTP_TARGET : "/hello/123" ,
250+ HTTP_ROUTE : "/hello/<int:helloid>" ,
225251 }
226252 )
227253 self .client .get ("/hello/123" )
@@ -235,8 +261,8 @@ def test_simple(self):
235261 def test_simple_new_semconv (self ):
236262 expected_attrs = expected_attributes_new (
237263 {
238- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
239- SpanAttributes . URL_SCHEME : "http" ,
264+ HTTP_ROUTE : "/hello/<int:helloid>" ,
265+ URL_SCHEME : "http" ,
240266 }
241267 )
242268 self .client .get ("/hello/123" )
@@ -250,15 +276,15 @@ def test_simple_new_semconv(self):
250276 def test_simple_both_semconv (self ):
251277 expected_attrs = expected_attributes (
252278 {
253- SpanAttributes . HTTP_TARGET : "/hello/123" ,
254- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
279+ HTTP_TARGET : "/hello/123" ,
280+ HTTP_ROUTE : "/hello/<int:helloid>" ,
255281 }
256282 )
257283 expected_attrs .update (
258284 expected_attributes_new (
259285 {
260- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
261- SpanAttributes . URL_SCHEME : "http" ,
286+ HTTP_ROUTE : "/hello/<int:helloid>" ,
287+ URL_SCHEME : "http" ,
262288 }
263289 )
264290 )
@@ -301,9 +327,9 @@ def test_not_recording(self):
301327 def test_404 (self ):
302328 expected_attrs = expected_attributes (
303329 {
304- SpanAttributes . HTTP_METHOD : "POST" ,
305- SpanAttributes . HTTP_TARGET : "/bye" ,
306- SpanAttributes . HTTP_STATUS_CODE : 404 ,
330+ HTTP_METHOD : "POST" ,
331+ HTTP_TARGET : "/bye" ,
332+ HTTP_STATUS_CODE : 404 ,
307333 }
308334 )
309335
@@ -319,10 +345,10 @@ def test_404(self):
319345 def test_404_new_semconv (self ):
320346 expected_attrs = expected_attributes_new (
321347 {
322- SpanAttributes . HTTP_REQUEST_METHOD : "POST" ,
323- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 404 ,
324- SpanAttributes . URL_PATH : "/bye" ,
325- SpanAttributes . URL_SCHEME : "http" ,
348+ HTTP_REQUEST_METHOD : "POST" ,
349+ HTTP_RESPONSE_STATUS_CODE : 404 ,
350+ URL_PATH : "/bye" ,
351+ URL_SCHEME : "http" ,
326352 }
327353 )
328354
@@ -338,18 +364,18 @@ def test_404_new_semconv(self):
338364 def test_404_both_semconv (self ):
339365 expected_attrs = expected_attributes (
340366 {
341- SpanAttributes . HTTP_METHOD : "POST" ,
342- SpanAttributes . HTTP_TARGET : "/bye" ,
343- SpanAttributes . HTTP_STATUS_CODE : 404 ,
367+ HTTP_METHOD : "POST" ,
368+ HTTP_TARGET : "/bye" ,
369+ HTTP_STATUS_CODE : 404 ,
344370 }
345371 )
346372 expected_attrs .update (
347373 expected_attributes_new (
348374 {
349- SpanAttributes . HTTP_REQUEST_METHOD : "POST" ,
350- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 404 ,
351- SpanAttributes . URL_PATH : "/bye" ,
352- SpanAttributes . URL_SCHEME : "http" ,
375+ HTTP_REQUEST_METHOD : "POST" ,
376+ HTTP_RESPONSE_STATUS_CODE : 404 ,
377+ URL_PATH : "/bye" ,
378+ URL_SCHEME : "http" ,
353379 }
354380 )
355381 )
@@ -366,9 +392,9 @@ def test_404_both_semconv(self):
366392 def test_internal_error (self ):
367393 expected_attrs = expected_attributes (
368394 {
369- SpanAttributes . HTTP_TARGET : "/hello/500" ,
370- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
371- SpanAttributes . HTTP_STATUS_CODE : 500 ,
395+ HTTP_TARGET : "/hello/500" ,
396+ HTTP_ROUTE : "/hello/<int:helloid>" ,
397+ HTTP_STATUS_CODE : 500 ,
372398 }
373399 )
374400 resp = self .client .get ("/hello/500" )
@@ -383,11 +409,11 @@ def test_internal_error(self):
383409 def test_internal_error_new_semconv (self ):
384410 expected_attrs = expected_attributes_new (
385411 {
386- SpanAttributes . URL_PATH : "/hello/500" ,
387- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
388- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 500 ,
412+ URL_PATH : "/hello/500" ,
413+ HTTP_ROUTE : "/hello/<int:helloid>" ,
414+ HTTP_RESPONSE_STATUS_CODE : 500 ,
389415 ERROR_TYPE : "500" ,
390- SpanAttributes . URL_SCHEME : "http" ,
416+ URL_SCHEME : "http" ,
391417 }
392418 )
393419 resp = self .client .get ("/hello/500" )
@@ -402,18 +428,18 @@ def test_internal_error_new_semconv(self):
402428 def test_internal_error_both_semconv (self ):
403429 expected_attrs = expected_attributes (
404430 {
405- SpanAttributes . HTTP_TARGET : "/hello/500" ,
406- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
407- SpanAttributes . HTTP_STATUS_CODE : 500 ,
431+ HTTP_TARGET : "/hello/500" ,
432+ HTTP_ROUTE : "/hello/<int:helloid>" ,
433+ HTTP_STATUS_CODE : 500 ,
408434 }
409435 )
410436 expected_attrs .update (
411437 expected_attributes_new (
412438 {
413- SpanAttributes . URL_PATH : "/hello/500" ,
414- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 500 ,
439+ URL_PATH : "/hello/500" ,
440+ HTTP_RESPONSE_STATUS_CODE : 500 ,
415441 ERROR_TYPE : "500" ,
416- SpanAttributes . URL_SCHEME : "http" ,
442+ URL_SCHEME : "http" ,
417443 }
418444 )
419445 )
0 commit comments