21
21
import opentelemetry .ext .flask as otel_flask
22
22
from opentelemetry import trace as trace_api
23
23
from opentelemetry .ext .testutil .wsgitestutil import WsgiTestBase
24
+ from opentelemetry .sdk .trace import MAX_NUM_ATTRIBUTES
25
+ from opentelemetry .sdk .util import BoundedDict
24
26
25
27
26
28
class TestFlaskIntegration (WsgiTestBase ):
@@ -40,15 +42,22 @@ def hello_endpoint(helloid):
40
42
self .client = Client (self .app , BaseResponse )
41
43
42
44
def test_simple (self ):
43
- expected_attrs = {
44
- "component" : "http" ,
45
- "http.method" : "GET" ,
46
- "http.host" : "localhost" ,
47
- "http.url" : "http://localhost/hello/123" ,
48
- "http.route" : "/hello/<int:helloid>" ,
49
- "http.status_code" : 200 ,
50
- "http.status_text" : "OK" ,
51
- }
45
+ expected_attrs = BoundedDict .from_map (
46
+ MAX_NUM_ATTRIBUTES ,
47
+ {
48
+ "component" : "http" ,
49
+ "http.method" : "GET" ,
50
+ "http.server_name" : "localhost" ,
51
+ "http.scheme" : "http" ,
52
+ "host.port" : 80 ,
53
+ "http.host" : "localhost" ,
54
+ "http.target" : "/hello/123" ,
55
+ "http.flavor" : "1.1" ,
56
+ "http.route" : "/hello/<int:helloid>" ,
57
+ "http.status_text" : "OK" ,
58
+ "http.status_code" : 200 ,
59
+ },
60
+ )
52
61
resp = self .client .get ("/hello/123" )
53
62
self .assertEqual (200 , resp .status_code )
54
63
self .assertEqual ([b"Hello: 123" ], list (resp .response ))
@@ -59,14 +68,21 @@ def test_simple(self):
59
68
self .assertEqual (span_list [0 ].attributes , expected_attrs )
60
69
61
70
def test_404 (self ):
62
- expected_attrs = {
63
- "component" : "http" ,
64
- "http.method" : "POST" ,
65
- "http.host" : "localhost" ,
66
- "http.url" : "http://localhost/bye" ,
67
- "http.status_code" : 404 ,
68
- "http.status_text" : "NOT FOUND" ,
69
- }
71
+ expected_attrs = BoundedDict .from_map (
72
+ MAX_NUM_ATTRIBUTES ,
73
+ {
74
+ "component" : "http" ,
75
+ "http.method" : "POST" ,
76
+ "http.server_name" : "localhost" ,
77
+ "http.scheme" : "http" ,
78
+ "host.port" : 80 ,
79
+ "http.host" : "localhost" ,
80
+ "http.target" : "/bye" ,
81
+ "http.flavor" : "1.1" ,
82
+ "http.status_text" : "NOT FOUND" ,
83
+ "http.status_code" : 404 ,
84
+ },
85
+ )
70
86
resp = self .client .post ("/bye" )
71
87
self .assertEqual (404 , resp .status_code )
72
88
resp .close ()
@@ -77,15 +93,22 @@ def test_404(self):
77
93
self .assertEqual (span_list [0 ].attributes , expected_attrs )
78
94
79
95
def test_internal_error (self ):
80
- expected_attrs = {
81
- "component" : "http" ,
82
- "http.method" : "GET" ,
83
- "http.host" : "localhost" ,
84
- "http.url" : "http://localhost/hello/500" ,
85
- "http.route" : "/hello/<int:helloid>" ,
86
- "http.status_code" : 500 ,
87
- "http.status_text" : "INTERNAL SERVER ERROR" ,
88
- }
96
+ expected_attrs = BoundedDict .from_map (
97
+ MAX_NUM_ATTRIBUTES ,
98
+ {
99
+ "component" : "http" ,
100
+ "http.method" : "GET" ,
101
+ "http.server_name" : "localhost" ,
102
+ "http.scheme" : "http" ,
103
+ "host.port" : 80 ,
104
+ "http.host" : "localhost" ,
105
+ "http.target" : "/hello/500" ,
106
+ "http.flavor" : "1.1" ,
107
+ "http.route" : "/hello/<int:helloid>" ,
108
+ "http.status_text" : "INTERNAL SERVER ERROR" ,
109
+ "http.status_code" : 500 ,
110
+ },
111
+ )
89
112
resp = self .client .get ("/hello/500" )
90
113
self .assertEqual (500 , resp .status_code )
91
114
resp .close ()
0 commit comments