2828 NumberDataPoint ,
2929)
3030from opentelemetry .sdk .resources import Resource
31- from opentelemetry .semconv .trace import SpanAttributes
31+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
32+ HTTP_FLAVOR ,
33+ HTTP_ROUTE ,
34+ HTTP_TARGET ,
35+ HTTP_URL ,
36+ )
3237from opentelemetry .test .globals_test import reset_trace_globals
3338from opentelemetry .test .test_base import TestBase
3439from opentelemetry .trace import (
@@ -122,22 +127,17 @@ def test_sub_app_starlette_call(self):
122127 spans_with_http_attributes = [
123128 span
124129 for span in spans
125- if (
126- SpanAttributes .HTTP_URL in span .attributes
127- or SpanAttributes .HTTP_TARGET in span .attributes
128- )
130+ if (HTTP_URL in span .attributes or HTTP_TARGET in span .attributes )
129131 ]
130132
131133 # expect only one span to have the attributes
132134 self .assertEqual (1 , len (spans_with_http_attributes ))
133135
134136 for span in spans_with_http_attributes :
135- self .assertEqual (
136- "/sub/home" , span .attributes [SpanAttributes .HTTP_TARGET ]
137- )
137+ self .assertEqual ("/sub/home" , span .attributes [HTTP_TARGET ])
138138 self .assertEqual (
139139 "http://testserver/sub/home" ,
140- span .attributes [SpanAttributes . HTTP_URL ],
140+ span .attributes [HTTP_URL ],
141141 )
142142
143143 def test_starlette_route_attribute_added (self ):
@@ -147,14 +147,10 @@ def test_starlette_route_attribute_added(self):
147147 self .assertEqual (len (spans ), 3 )
148148 for span in spans :
149149 self .assertIn ("GET /user/{username}" , span .name )
150- self .assertEqual (
151- spans [- 1 ].attributes [SpanAttributes .HTTP_ROUTE ], "/user/{username}"
152- )
150+ self .assertEqual (spans [- 1 ].attributes [HTTP_ROUTE ], "/user/{username}" )
153151 # ensure that at least one attribute that is populated by
154152 # the asgi instrumentation is successfully feeding though.
155- self .assertEqual (
156- spans [- 1 ].attributes [SpanAttributes .HTTP_FLAVOR ], "1.1"
157- )
153+ self .assertEqual (spans [- 1 ].attributes [HTTP_FLAVOR ], "1.1" )
158154
159155 def test_starlette_excluded_urls (self ):
160156 """Ensure that given starlette routes are excluded."""
@@ -456,10 +452,7 @@ def test_sub_app_starlette_call(self):
456452 spans_with_http_attributes = [
457453 span
458454 for span in spans
459- if (
460- SpanAttributes .HTTP_URL in span .attributes
461- or SpanAttributes .HTTP_TARGET in span .attributes
462- )
455+ if (HTTP_URL in span .attributes or HTTP_TARGET in span .attributes )
463456 ]
464457
465458 # We now expect spans with attributes from both the app and its sub app
@@ -480,12 +473,10 @@ def test_sub_app_starlette_call(self):
480473 self .assertIsNotNone (server_span )
481474 # As soon as the bug is fixed for starlette, we can iterate over spans_with_http_attributes here
482475 # to verify the correctness of the attributes for the internal span as well
483- self .assertEqual (
484- "/sub/home" , server_span .attributes [SpanAttributes .HTTP_TARGET ]
485- )
476+ self .assertEqual ("/sub/home" , server_span .attributes [HTTP_TARGET ])
486477 self .assertEqual (
487478 "http://testserver/sub/home" ,
488- server_span .attributes [SpanAttributes . HTTP_URL ],
479+ server_span .attributes [HTTP_URL ],
489480 )
490481
491482
@@ -542,10 +533,7 @@ def test_sub_app_starlette_call(self):
542533 spans_with_http_attributes = [
543534 span
544535 for span in spans
545- if (
546- SpanAttributes .HTTP_URL in span .attributes
547- or SpanAttributes .HTTP_TARGET in span .attributes
548- )
536+ if (HTTP_URL in span .attributes or HTTP_TARGET in span .attributes )
549537 ]
550538
551539 # We now expect spans with attributes from both the app and its sub app
@@ -566,12 +554,10 @@ def test_sub_app_starlette_call(self):
566554 self .assertIsNotNone (server_span )
567555 # As soon as the bug is fixed for starlette, we can iterate over spans_with_http_attributes here
568556 # to verify the correctness of the attributes for the internal span as well
569- self .assertEqual (
570- "/sub/home" , server_span .attributes [SpanAttributes .HTTP_TARGET ]
571- )
557+ self .assertEqual ("/sub/home" , server_span .attributes [HTTP_TARGET ])
572558 self .assertEqual (
573559 "http://testserver/sub/home" ,
574- server_span .attributes [SpanAttributes . HTTP_URL ],
560+ server_span .attributes [HTTP_URL ],
575561 )
576562
577563
0 commit comments