28
28
NumberDataPoint ,
29
29
)
30
30
from 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
+ )
32
37
from opentelemetry .test .globals_test import reset_trace_globals
33
38
from opentelemetry .test .test_base import TestBase
34
39
from opentelemetry .trace import (
@@ -122,22 +127,17 @@ def test_sub_app_starlette_call(self):
122
127
spans_with_http_attributes = [
123
128
span
124
129
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 )
129
131
]
130
132
131
133
# expect only one span to have the attributes
132
134
self .assertEqual (1 , len (spans_with_http_attributes ))
133
135
134
136
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 ])
138
138
self .assertEqual (
139
139
"http://testserver/sub/home" ,
140
- span .attributes [SpanAttributes . HTTP_URL ],
140
+ span .attributes [HTTP_URL ],
141
141
)
142
142
143
143
def test_starlette_route_attribute_added (self ):
@@ -147,14 +147,10 @@ def test_starlette_route_attribute_added(self):
147
147
self .assertEqual (len (spans ), 3 )
148
148
for span in spans :
149
149
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}" )
153
151
# ensure that at least one attribute that is populated by
154
152
# 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" )
158
154
159
155
def test_starlette_excluded_urls (self ):
160
156
"""Ensure that given starlette routes are excluded."""
@@ -456,10 +452,7 @@ def test_sub_app_starlette_call(self):
456
452
spans_with_http_attributes = [
457
453
span
458
454
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 )
463
456
]
464
457
465
458
# 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):
480
473
self .assertIsNotNone (server_span )
481
474
# As soon as the bug is fixed for starlette, we can iterate over spans_with_http_attributes here
482
475
# 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 ])
486
477
self .assertEqual (
487
478
"http://testserver/sub/home" ,
488
- server_span .attributes [SpanAttributes . HTTP_URL ],
479
+ server_span .attributes [HTTP_URL ],
489
480
)
490
481
491
482
@@ -542,10 +533,7 @@ def test_sub_app_starlette_call(self):
542
533
spans_with_http_attributes = [
543
534
span
544
535
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 )
549
537
]
550
538
551
539
# 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):
566
554
self .assertIsNotNone (server_span )
567
555
# As soon as the bug is fixed for starlette, we can iterate over spans_with_http_attributes here
568
556
# 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 ])
572
558
self .assertEqual (
573
559
"http://testserver/sub/home" ,
574
- server_span .attributes [SpanAttributes . HTTP_URL ],
560
+ server_span .attributes [HTTP_URL ],
575
561
)
576
562
577
563
0 commit comments