40
40
NumberDataPoint ,
41
41
)
42
42
from 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
+ )
43
70
from opentelemetry .semconv .attributes .error_attributes import ERROR_TYPE
44
- from opentelemetry .semconv .trace import SpanAttributes
45
71
from opentelemetry .test .wsgitestutil import WsgiTestBase
46
72
from opentelemetry .util .http import (
47
73
OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS ,
57
83
58
84
def expected_attributes (override_attributes ):
59
85
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 ,
69
95
}
70
96
for key , val in override_attributes .items ():
71
97
default_attributes [key ] = val
@@ -74,12 +100,12 @@ def expected_attributes(override_attributes):
74
100
75
101
def expected_attributes_new (override_attributes ):
76
102
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 ,
83
109
}
84
110
for key , val in override_attributes .items ():
85
111
default_attributes [key ] = val
@@ -220,8 +246,8 @@ def assert_environ():
220
246
def test_simple (self ):
221
247
expected_attrs = expected_attributes (
222
248
{
223
- SpanAttributes . HTTP_TARGET : "/hello/123" ,
224
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
249
+ HTTP_TARGET : "/hello/123" ,
250
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
225
251
}
226
252
)
227
253
self .client .get ("/hello/123" )
@@ -235,8 +261,8 @@ def test_simple(self):
235
261
def test_simple_new_semconv (self ):
236
262
expected_attrs = expected_attributes_new (
237
263
{
238
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
239
- SpanAttributes . URL_SCHEME : "http" ,
264
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
265
+ URL_SCHEME : "http" ,
240
266
}
241
267
)
242
268
self .client .get ("/hello/123" )
@@ -250,15 +276,15 @@ def test_simple_new_semconv(self):
250
276
def test_simple_both_semconv (self ):
251
277
expected_attrs = expected_attributes (
252
278
{
253
- SpanAttributes . HTTP_TARGET : "/hello/123" ,
254
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
279
+ HTTP_TARGET : "/hello/123" ,
280
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
255
281
}
256
282
)
257
283
expected_attrs .update (
258
284
expected_attributes_new (
259
285
{
260
- SpanAttributes . HTTP_ROUTE : "/hello/<int:helloid>" ,
261
- SpanAttributes . URL_SCHEME : "http" ,
286
+ HTTP_ROUTE : "/hello/<int:helloid>" ,
287
+ URL_SCHEME : "http" ,
262
288
}
263
289
)
264
290
)
@@ -301,9 +327,9 @@ def test_not_recording(self):
301
327
def test_404 (self ):
302
328
expected_attrs = expected_attributes (
303
329
{
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 ,
307
333
}
308
334
)
309
335
@@ -319,10 +345,10 @@ def test_404(self):
319
345
def test_404_new_semconv (self ):
320
346
expected_attrs = expected_attributes_new (
321
347
{
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" ,
326
352
}
327
353
)
328
354
@@ -338,18 +364,18 @@ def test_404_new_semconv(self):
338
364
def test_404_both_semconv (self ):
339
365
expected_attrs = expected_attributes (
340
366
{
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 ,
344
370
}
345
371
)
346
372
expected_attrs .update (
347
373
expected_attributes_new (
348
374
{
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" ,
353
379
}
354
380
)
355
381
)
@@ -366,9 +392,9 @@ def test_404_both_semconv(self):
366
392
def test_internal_error (self ):
367
393
expected_attrs = expected_attributes (
368
394
{
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 ,
372
398
}
373
399
)
374
400
resp = self .client .get ("/hello/500" )
@@ -383,11 +409,11 @@ def test_internal_error(self):
383
409
def test_internal_error_new_semconv (self ):
384
410
expected_attrs = expected_attributes_new (
385
411
{
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 ,
389
415
ERROR_TYPE : "500" ,
390
- SpanAttributes . URL_SCHEME : "http" ,
416
+ URL_SCHEME : "http" ,
391
417
}
392
418
)
393
419
resp = self .client .get ("/hello/500" )
@@ -402,18 +428,18 @@ def test_internal_error_new_semconv(self):
402
428
def test_internal_error_both_semconv (self ):
403
429
expected_attrs = expected_attributes (
404
430
{
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 ,
408
434
}
409
435
)
410
436
expected_attrs .update (
411
437
expected_attributes_new (
412
438
{
413
- SpanAttributes . URL_PATH : "/hello/500" ,
414
- SpanAttributes . HTTP_RESPONSE_STATUS_CODE : 500 ,
439
+ URL_PATH : "/hello/500" ,
440
+ HTTP_RESPONSE_STATUS_CODE : 500 ,
415
441
ERROR_TYPE : "500" ,
416
- SpanAttributes . URL_SCHEME : "http" ,
442
+ URL_SCHEME : "http" ,
417
443
}
418
444
)
419
445
)
0 commit comments