46
46
NumberDataPoint ,
47
47
)
48
48
from opentelemetry .sdk .resources import Resource
49
+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
50
+ HTTP_FLAVOR ,
51
+ HTTP_HOST ,
52
+ HTTP_METHOD ,
53
+ HTTP_SCHEME ,
54
+ HTTP_SERVER_NAME ,
55
+ HTTP_STATUS_CODE ,
56
+ HTTP_TARGET ,
57
+ HTTP_URL ,
58
+ )
59
+ from opentelemetry .semconv ._incubating .attributes .net_attributes import NET_HOST_PORT
49
60
from opentelemetry .semconv .attributes .http_attributes import (
50
61
HTTP_REQUEST_METHOD ,
51
62
HTTP_RESPONSE_STATUS_CODE ,
55
66
NETWORK_PROTOCOL_VERSION ,
56
67
)
57
68
from opentelemetry .semconv .attributes .url_attributes import URL_SCHEME
58
- from opentelemetry .semconv .trace import SpanAttributes
59
69
from opentelemetry .test .globals_test import reset_trace_globals
60
70
from opentelemetry .test .test_base import TestBase
61
71
from opentelemetry .util ._importlib_metadata import entry_points
85
95
"http.server.active_requests" : _server_active_requests_count_attrs_old ,
86
96
"http.server.duration" : {
87
97
* _server_duration_attrs_old ,
88
- SpanAttributes . HTTP_TARGET ,
98
+ HTTP_TARGET ,
89
99
},
90
100
"http.server.response.size" : {
91
101
* _server_duration_attrs_old ,
92
- SpanAttributes . HTTP_TARGET ,
102
+ HTTP_TARGET ,
93
103
},
94
104
"http.server.request.size" : {
95
105
* _server_duration_attrs_old ,
96
- SpanAttributes . HTTP_TARGET ,
106
+ HTTP_TARGET ,
97
107
},
98
108
}
99
109
@@ -245,8 +255,8 @@ def test_sub_app_fastapi_call(self):
245
255
span
246
256
for span in spans
247
257
if (
248
- SpanAttributes . HTTP_URL in span .attributes
249
- or SpanAttributes . HTTP_TARGET in span .attributes
258
+ HTTP_URL in span .attributes
259
+ or HTTP_TARGET in span .attributes
250
260
)
251
261
]
252
262
@@ -256,11 +266,11 @@ def test_sub_app_fastapi_call(self):
256
266
257
267
for span in spans_with_http_attributes :
258
268
self .assertEqual (
259
- "/sub/home" , span .attributes [SpanAttributes . HTTP_TARGET ]
269
+ "/sub/home" , span .attributes [HTTP_TARGET ]
260
270
)
261
271
self .assertEqual (
262
272
"https://testserver:443/sub/home" ,
263
- span .attributes [SpanAttributes . HTTP_URL ],
273
+ span .attributes [HTTP_URL ],
264
274
)
265
275
266
276
@@ -309,8 +319,8 @@ def test_sub_app_fastapi_call(self):
309
319
span
310
320
for span in spans
311
321
if (
312
- SpanAttributes . HTTP_URL in span .attributes
313
- or SpanAttributes . HTTP_TARGET in span .attributes
322
+ HTTP_URL in span .attributes
323
+ or HTTP_TARGET in span .attributes
314
324
)
315
325
]
316
326
@@ -319,11 +329,11 @@ def test_sub_app_fastapi_call(self):
319
329
320
330
for span in spans_with_http_attributes :
321
331
self .assertEqual (
322
- "/sub/home" , span .attributes [SpanAttributes . HTTP_TARGET ]
332
+ "/sub/home" , span .attributes [HTTP_TARGET ]
323
333
)
324
334
self .assertEqual (
325
335
"https://testserver:443/sub/home" ,
326
- span .attributes [SpanAttributes . HTTP_URL ],
336
+ span .attributes [HTTP_URL ],
327
337
)
328
338
329
339
@@ -382,12 +392,12 @@ def test_fastapi_route_attribute_added(self):
382
392
for span in spans :
383
393
self .assertIn ("GET /user/{username}" , span .name )
384
394
self .assertEqual (
385
- spans [- 1 ].attributes [SpanAttributes . HTTP_ROUTE ], "/user/{username}"
395
+ spans [- 1 ].attributes [HTTP_ROUTE ], "/user/{username}"
386
396
)
387
397
# ensure that at least one attribute that is populated by
388
398
# the asgi instrumentation is successfully feeding though.
389
399
self .assertEqual (
390
- spans [- 1 ].attributes [SpanAttributes . HTTP_FLAVOR ], "1.1"
400
+ spans [- 1 ].attributes [HTTP_FLAVOR ], "1.1"
391
401
)
392
402
393
403
def test_fastapi_excluded_urls (self ):
@@ -511,21 +521,21 @@ def test_basic_metric_success(self):
511
521
self ._client .get ("/foobar" )
512
522
duration = max (round ((default_timer () - start ) * 1000 ), 0 )
513
523
expected_duration_attributes = {
514
- SpanAttributes . HTTP_METHOD : "GET" ,
515
- SpanAttributes . HTTP_HOST : "testserver:443" ,
516
- SpanAttributes . HTTP_SCHEME : "https" ,
517
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
518
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
519
- SpanAttributes . NET_HOST_PORT : 443 ,
520
- SpanAttributes . HTTP_STATUS_CODE : 200 ,
521
- SpanAttributes . HTTP_TARGET : "/foobar" ,
524
+ HTTP_METHOD : "GET" ,
525
+ HTTP_HOST : "testserver:443" ,
526
+ HTTP_SCHEME : "https" ,
527
+ HTTP_FLAVOR : "1.1" ,
528
+ HTTP_SERVER_NAME : "testserver" ,
529
+ NET_HOST_PORT : 443 ,
530
+ HTTP_STATUS_CODE : 200 ,
531
+ HTTP_TARGET : "/foobar" ,
522
532
}
523
533
expected_requests_count_attributes = {
524
- SpanAttributes . HTTP_METHOD : "GET" ,
525
- SpanAttributes . HTTP_HOST : "testserver:443" ,
526
- SpanAttributes . HTTP_SCHEME : "https" ,
527
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
528
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
534
+ HTTP_METHOD : "GET" ,
535
+ HTTP_HOST : "testserver:443" ,
536
+ HTTP_SCHEME : "https" ,
537
+ HTTP_FLAVOR : "1.1" ,
538
+ HTTP_SERVER_NAME : "testserver" ,
529
539
}
530
540
metrics_list = self .memory_metrics_reader .get_metrics_data ()
531
541
for metric in (
@@ -593,14 +603,14 @@ def test_basic_metric_success_both_semconv(self):
593
603
duration = max (round ((default_timer () - start ) * 1000 ), 0 )
594
604
duration_s = max (default_timer () - start , 0 )
595
605
expected_duration_attributes_old = {
596
- SpanAttributes . HTTP_METHOD : "GET" ,
597
- SpanAttributes . HTTP_HOST : "testserver:443" ,
598
- SpanAttributes . HTTP_SCHEME : "https" ,
599
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
600
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
601
- SpanAttributes . NET_HOST_PORT : 443 ,
602
- SpanAttributes . HTTP_STATUS_CODE : 200 ,
603
- SpanAttributes . HTTP_TARGET : "/foobar" ,
606
+ HTTP_METHOD : "GET" ,
607
+ HTTP_HOST : "testserver:443" ,
608
+ HTTP_SCHEME : "https" ,
609
+ HTTP_FLAVOR : "1.1" ,
610
+ HTTP_SERVER_NAME : "testserver" ,
611
+ NET_HOST_PORT : 443 ,
612
+ HTTP_STATUS_CODE : 200 ,
613
+ HTTP_TARGET : "/foobar" ,
604
614
}
605
615
expected_duration_attributes_new = {
606
616
HTTP_REQUEST_METHOD : "GET" ,
@@ -610,11 +620,11 @@ def test_basic_metric_success_both_semconv(self):
610
620
HTTP_ROUTE : "/foobar" ,
611
621
}
612
622
expected_requests_count_attributes = {
613
- SpanAttributes . HTTP_METHOD : "GET" ,
614
- SpanAttributes . HTTP_HOST : "testserver:443" ,
615
- SpanAttributes . HTTP_SCHEME : "https" ,
616
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
617
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
623
+ HTTP_METHOD : "GET" ,
624
+ HTTP_HOST : "testserver:443" ,
625
+ HTTP_SCHEME : "https" ,
626
+ HTTP_FLAVOR : "1.1" ,
627
+ HTTP_SERVER_NAME : "testserver" ,
618
628
HTTP_REQUEST_METHOD : "GET" ,
619
629
URL_SCHEME : "https" ,
620
630
}
@@ -676,21 +686,21 @@ def test_basic_metric_nonstandard_http_method_success(self):
676
686
self ._client .request ("NONSTANDARD" , "/foobar" )
677
687
duration = max (round ((default_timer () - start ) * 1000 ), 0 )
678
688
expected_duration_attributes = {
679
- SpanAttributes . HTTP_METHOD : "_OTHER" ,
680
- SpanAttributes . HTTP_HOST : "testserver:443" ,
681
- SpanAttributes . HTTP_SCHEME : "https" ,
682
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
683
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
684
- SpanAttributes . NET_HOST_PORT : 443 ,
685
- SpanAttributes . HTTP_STATUS_CODE : 405 ,
686
- SpanAttributes . HTTP_TARGET : "/foobar" ,
689
+ HTTP_METHOD : "_OTHER" ,
690
+ HTTP_HOST : "testserver:443" ,
691
+ HTTP_SCHEME : "https" ,
692
+ HTTP_FLAVOR : "1.1" ,
693
+ HTTP_SERVER_NAME : "testserver" ,
694
+ NET_HOST_PORT : 443 ,
695
+ HTTP_STATUS_CODE : 405 ,
696
+ HTTP_TARGET : "/foobar" ,
687
697
}
688
698
expected_requests_count_attributes = {
689
- SpanAttributes . HTTP_METHOD : "_OTHER" ,
690
- SpanAttributes . HTTP_HOST : "testserver:443" ,
691
- SpanAttributes . HTTP_SCHEME : "https" ,
692
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
693
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
699
+ HTTP_METHOD : "_OTHER" ,
700
+ HTTP_HOST : "testserver:443" ,
701
+ HTTP_SCHEME : "https" ,
702
+ HTTP_FLAVOR : "1.1" ,
703
+ HTTP_SERVER_NAME : "testserver" ,
694
704
}
695
705
metrics_list = self .memory_metrics_reader .get_metrics_data ()
696
706
for metric in (
@@ -758,14 +768,14 @@ def test_basic_metric_nonstandard_http_method_success_both_semconv(self):
758
768
duration = max (round ((default_timer () - start ) * 1000 ), 0 )
759
769
duration_s = max (default_timer () - start , 0 )
760
770
expected_duration_attributes_old = {
761
- SpanAttributes . HTTP_METHOD : "_OTHER" ,
762
- SpanAttributes . HTTP_HOST : "testserver:443" ,
763
- SpanAttributes . HTTP_SCHEME : "https" ,
764
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
765
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
766
- SpanAttributes . NET_HOST_PORT : 443 ,
767
- SpanAttributes . HTTP_STATUS_CODE : 405 ,
768
- SpanAttributes . HTTP_TARGET : "/foobar" ,
771
+ HTTP_METHOD : "_OTHER" ,
772
+ HTTP_HOST : "testserver:443" ,
773
+ HTTP_SCHEME : "https" ,
774
+ HTTP_FLAVOR : "1.1" ,
775
+ HTTP_SERVER_NAME : "testserver" ,
776
+ NET_HOST_PORT : 443 ,
777
+ HTTP_STATUS_CODE : 405 ,
778
+ HTTP_TARGET : "/foobar" ,
769
779
}
770
780
expected_duration_attributes_new = {
771
781
HTTP_REQUEST_METHOD : "_OTHER" ,
@@ -775,11 +785,11 @@ def test_basic_metric_nonstandard_http_method_success_both_semconv(self):
775
785
HTTP_ROUTE : "/foobar" ,
776
786
}
777
787
expected_requests_count_attributes = {
778
- SpanAttributes . HTTP_METHOD : "_OTHER" ,
779
- SpanAttributes . HTTP_HOST : "testserver:443" ,
780
- SpanAttributes . HTTP_SCHEME : "https" ,
781
- SpanAttributes . HTTP_FLAVOR : "1.1" ,
782
- SpanAttributes . HTTP_SERVER_NAME : "testserver" ,
788
+ HTTP_METHOD : "_OTHER" ,
789
+ HTTP_HOST : "testserver:443" ,
790
+ HTTP_SCHEME : "https" ,
791
+ HTTP_FLAVOR : "1.1" ,
792
+ HTTP_SERVER_NAME : "testserver" ,
783
793
HTTP_REQUEST_METHOD : "_OTHER" ,
784
794
URL_SCHEME : "https" ,
785
795
}
@@ -1204,8 +1214,8 @@ def test_sub_app_fastapi_call(self):
1204
1214
span
1205
1215
for span in spans
1206
1216
if (
1207
- SpanAttributes . HTTP_URL in span .attributes
1208
- or SpanAttributes . HTTP_TARGET in span .attributes
1217
+ HTTP_URL in span .attributes
1218
+ or HTTP_TARGET in span .attributes
1209
1219
)
1210
1220
]
1211
1221
@@ -1214,11 +1224,11 @@ def test_sub_app_fastapi_call(self):
1214
1224
1215
1225
for span in spans_with_http_attributes :
1216
1226
self .assertEqual (
1217
- "/sub/home" , span .attributes [SpanAttributes . HTTP_TARGET ]
1227
+ "/sub/home" , span .attributes [HTTP_TARGET ]
1218
1228
)
1219
1229
self .assertEqual (
1220
1230
"https://testserver:443/sub/home" ,
1221
- span .attributes [SpanAttributes . HTTP_URL ],
1231
+ span .attributes [HTTP_URL ],
1222
1232
)
1223
1233
1224
1234
@@ -1297,8 +1307,8 @@ def test_sub_app_fastapi_call(self):
1297
1307
span
1298
1308
for span in spans
1299
1309
if (
1300
- SpanAttributes . HTTP_URL in span .attributes
1301
- or SpanAttributes . HTTP_TARGET in span .attributes
1310
+ HTTP_URL in span .attributes
1311
+ or HTTP_TARGET in span .attributes
1302
1312
)
1303
1313
]
1304
1314
@@ -1307,11 +1317,11 @@ def test_sub_app_fastapi_call(self):
1307
1317
1308
1318
for span in spans_with_http_attributes :
1309
1319
self .assertEqual (
1310
- "/sub/home" , span .attributes [SpanAttributes . HTTP_TARGET ]
1320
+ "/sub/home" , span .attributes [HTTP_TARGET ]
1311
1321
)
1312
1322
self .assertEqual (
1313
1323
"https://testserver:443/sub/home" ,
1314
- span .attributes [SpanAttributes . HTTP_URL ],
1324
+ span .attributes [HTTP_URL ],
1315
1325
)
1316
1326
1317
1327
0 commit comments