41
41
)
42
42
from opentelemetry .sdk .resources import Resource
43
43
from opentelemetry .semconv .attributes .error_attributes import ERROR_TYPE
44
- from opentelemetry .semconv .trace import SpanAttributes
44
+ from opentelemetry .semconv ._incubating .attributes .http_attributes import (
45
+ HTTP_METHOD ,
46
+ HTTP_SERVER_NAME ,
47
+ HTTP_SCHEME ,
48
+ HTTP_HOST ,
49
+ HTTP_TARGET ,
50
+ HTTP_FLAVOR ,
51
+ HTTP_STATUS_CODE ,
52
+ HTTP_REQUEST_METHOD ,
53
+ HTTP_RESPONSE_STATUS_CODE ,
54
+ HTTP_ROUTE ,
55
+
56
+
57
+ )
58
+ from opentelemetry .semconv ._incubating .attributes .net_attributes import (
59
+ NET_HOST_PORT ,
60
+ NET_HOST_NAME ,
61
+
62
+ )
63
+ from opentelemetry .semconv ._incubating .attributes .server_attributes import (
64
+ SERVER_PORT ,
65
+ SERVER_ADDRESS ,
66
+ )
67
+ from opentelemetry .semconv ._incubating .attributes .url_attributes import (
68
+ URL_PATH ,
69
+ URL_SCHEME ,
70
+ )
71
+ from opentelemetry .semconv ._incubating .attributes .network_attributes import (
72
+ NETWORK_PROTOCOL_VERSION
73
+ )
45
74
from opentelemetry .test .wsgitestutil import WsgiTestBase
46
75
from opentelemetry .util .http import (
47
76
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ,
57
86
58
87
def expected_attributes (override_attributes ):
59
88
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 ,
89
+ HTTP_METHOD : "GET" ,
90
+ HTTP_SERVER_NAME : "localhost" ,
91
+ HTTP_SCHEME : "http" ,
92
+ NET_HOST_PORT : 80 ,
93
+ NET_HOST_NAME : "localhost" ,
94
+ HTTP_HOST : "localhost" ,
95
+ HTTP_TARGET : "/" ,
96
+ HTTP_FLAVOR : "1.1" ,
97
+ HTTP_STATUS_CODE : 200 ,
69
98
}
70
99
for key , val in override_attributes .items ():
71
100
default_attributes [key ] = val
@@ -74,12 +103,12 @@ def expected_attributes(override_attributes):
74
103
75
104
def expected_attributes_new (override_attributes ):
76
105
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 ,
106
+ HTTP_REQUEST_METHOD : "GET" ,
107
+ SERVER_PORT : 80 ,
108
+ SERVER_ADDRESS : "localhost" ,
109
+ URL_PATH : "/hello/123" ,
110
+ NETWORK_PROTOCOL_VERSION : "1.1" ,
111
+ HTTP_RESPONSE_STATUS_CODE : 200 ,
83
112
}
84
113
for key , val in override_attributes .items ():
85
114
default_attributes [key ] = val
@@ -220,8 +249,8 @@ def assert_environ():
220
249
def test_simple (self ):
221
250
expected_attrs = expected_attributes (
222
251
{
223
- SpanAttributes . HTTP_TARGET : "/hello/123" ,
224
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
252
+ HTTP_TARGET : "/hello/123" ,
253
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
225
254
}
226
255
)
227
256
self .client .get ("/hello/123" )
@@ -235,8 +264,8 @@ def test_simple(self):
235
264
def test_simple_new_semconv (self ):
236
265
expected_attrs = expected_attributes_new (
237
266
{
238
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
239
- SpanAttributes . URL_SCHEME : "http" ,
267
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
268
+ URL_SCHEME : "http" ,
240
269
}
241
270
)
242
271
self .client .get ("/hello/123" )
@@ -250,15 +279,15 @@ def test_simple_new_semconv(self):
250
279
def test_simple_both_semconv (self ):
251
280
expected_attrs = expected_attributes (
252
281
{
253
- SpanAttributes . HTTP_TARGET : "/hello/123" ,
254
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
282
+ HTTP_TARGET : "/hello/123" ,
283
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
255
284
}
256
285
)
257
286
expected_attrs .update (
258
287
expected_attributes_new (
259
288
{
260
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
261
- SpanAttributes . URL_SCHEME : "http" ,
289
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
290
+ URL_SCHEME : "http" ,
262
291
}
263
292
)
264
293
)
@@ -301,9 +330,9 @@ def test_not_recording(self):
301
330
def test_404 (self ):
302
331
expected_attrs = expected_attributes (
303
332
{
304
- SpanAttributes . HTTP_METHOD : "POST" ,
305
- SpanAttributes . HTTP_TARGET : "/bye" ,
306
- SpanAttributes . HTTP_STATUS_CODE : 404 ,
333
+ HTTP_METHOD : "POST" ,
334
+ HTTP_TARGET : "/bye" ,
335
+ HTTP_STATUS_CODE : 404 ,
307
336
}
308
337
)
309
338
@@ -319,10 +348,10 @@ def test_404(self):
319
348
def test_404_new_semconv (self ):
320
349
expected_attrs = expected_attributes_new (
321
350
{
322
- SpanAttributes . HTTP_REQUEST_METHOD : "POST" ,
323
- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 404 ,
324
- SpanAttributes . URL_PATH : "/bye" ,
325
- SpanAttributes . URL_SCHEME : "http" ,
351
+ HTTP_REQUEST_METHOD : "POST" ,
352
+ HTTP_RESPONSE_STATUS_CODE : 404 ,
353
+ URL_PATH : "/bye" ,
354
+ URL_SCHEME : "http" ,
326
355
}
327
356
)
328
357
@@ -338,18 +367,18 @@ def test_404_new_semconv(self):
338
367
def test_404_both_semconv (self ):
339
368
expected_attrs = expected_attributes (
340
369
{
341
- SpanAttributes . HTTP_METHOD : "POST" ,
342
- SpanAttributes . HTTP_TARGET : "/bye" ,
343
- SpanAttributes . HTTP_STATUS_CODE : 404 ,
370
+ HTTP_METHOD : "POST" ,
371
+ HTTP_TARGET : "/bye" ,
372
+ HTTP_STATUS_CODE : 404 ,
344
373
}
345
374
)
346
375
expected_attrs .update (
347
376
expected_attributes_new (
348
377
{
349
- SpanAttributes . HTTP_REQUEST_METHOD : "POST" ,
350
- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 404 ,
351
- SpanAttributes . URL_PATH : "/bye" ,
352
- SpanAttributes . URL_SCHEME : "http" ,
378
+ HTTP_REQUEST_METHOD : "POST" ,
379
+ HTTP_RESPONSE_STATUS_CODE : 404 ,
380
+ URL_PATH : "/bye" ,
381
+ URL_SCHEME : "http" ,
353
382
}
354
383
)
355
384
)
@@ -366,9 +395,9 @@ def test_404_both_semconv(self):
366
395
def test_internal_error (self ):
367
396
expected_attrs = expected_attributes (
368
397
{
369
- SpanAttributes . HTTP_TARGET : "/hello/500" ,
370
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
371
- SpanAttributes . HTTP_STATUS_CODE : 500 ,
398
+ HTTP_TARGET : "/hello/500" ,
399
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
400
+ HTTP_STATUS_CODE : 500 ,
372
401
}
373
402
)
374
403
resp = self .client .get ("/hello/500" )
@@ -383,11 +412,11 @@ def test_internal_error(self):
383
412
def test_internal_error_new_semconv (self ):
384
413
expected_attrs = expected_attributes_new (
385
414
{
386
- SpanAttributes . URL_PATH : "/hello/500" ,
387
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
388
- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 500 ,
415
+ URL_PATH : "/hello/500" ,
416
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
417
+ HTTP_RESPONSE_STATUS_CODE : 500 ,
389
418
ERROR_TYPE : "500" ,
390
- SpanAttributes . URL_SCHEME : "http" ,
419
+ URL_SCHEME : "http" ,
391
420
}
392
421
)
393
422
resp = self .client .get ("/hello/500" )
@@ -402,18 +431,18 @@ def test_internal_error_new_semconv(self):
402
431
def test_internal_error_both_semconv (self ):
403
432
expected_attrs = expected_attributes (
404
433
{
405
- SpanAttributes . HTTP_TARGET : "/hello/500" ,
406
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
407
- SpanAttributes . HTTP_STATUS_CODE : 500 ,
434
+ HTTP_TARGET : "/hello/500" ,
435
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
436
+ HTTP_STATUS_CODE : 500 ,
408
437
}
409
438
)
410
439
expected_attrs .update (
411
440
expected_attributes_new (
412
441
{
413
- SpanAttributes . URL_PATH : "/hello/500" ,
414
- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 500 ,
442
+ URL_PATH : "/hello/500" ,
443
+ HTTP_RESPONSE_STATUS_CODE : 500 ,
415
444
ERROR_TYPE : "500" ,
416
- SpanAttributes . URL_SCHEME : "http" ,
445
+ URL_SCHEME : "http" ,
417
446
}
418
447
)
419
448
)
0 commit comments