@@ -51,6 +51,10 @@ def create_app():
5151 def index ():
5252 return 'test flask trace' # pragma: NO COVER
5353
54+ @app .route ('/wiki/<entry>' )
55+ def wiki (entry ):
56+ return 'test flask trace' # pragma: NO COVER
57+
5458 @app .route ('/_ah/health' )
5559 def health_check ():
5660 return 'test health check' # pragma: NO COVER
@@ -155,7 +159,6 @@ def test__before_request(self):
155159 'http.host' : u'localhost' ,
156160 'http.method' : u'GET' ,
157161 'http.path' : u'/wiki/Rabbit' ,
158- 'http.route' : u'/wiki/Rabbit' ,
159162 'http.url' : u'http://localhost/wiki/Rabbit' ,
160163 }
161164
@@ -220,7 +223,6 @@ def test_header_encoding(self):
220223 'http.host' : u'localhost' ,
221224 'http.method' : u'GET' ,
222225 'http.path' : u'/wiki/Rabbit' ,
223- 'http.route' : u'/wiki/Rabbit' ,
224226 'http.url' : u'http://localhost/wiki/Rabbit' ,
225227 }
226228
@@ -248,7 +250,6 @@ def test_header_is_none(self):
248250 'http.host' : u'localhost' ,
249251 'http.method' : u'GET' ,
250252 'http.path' : u'/wiki/Rabbit' ,
251- 'http.route' : u'/wiki/Rabbit' ,
252253 'http.url' : u'http://localhost/wiki/Rabbit' ,
253254 }
254255
@@ -278,13 +279,37 @@ def test__after_request_sampled(self):
278279 flask_trace_id = '00-{}-{}-00' .format (trace_id , span_id )
279280
280281 app = self .create_app ()
281- flask_middleware .FlaskMiddleware (app = app )
282+ flask_middleware .FlaskMiddleware (
283+ app = app ,
284+ sampler = samplers .AlwaysOnSampler ()
285+ )
282286
283- response = app .test_client ().get (
284- '/' ,
285- headers = {flask_trace_header : flask_trace_id })
287+ context = app .test_request_context (
288+ path = '/wiki/Rabbit' ,
289+ headers = {flask_trace_header : flask_trace_id }
290+ )
286291
287- self .assertEqual (response .status_code , 200 )
292+ with context :
293+ app .preprocess_request ()
294+ tracer = execution_context .get_opencensus_tracer ()
295+ self .assertIsNotNone (tracer )
296+
297+ span = tracer .current_span ()
298+
299+ rv = app .dispatch_request ()
300+ app .finalize_request (rv )
301+
302+ expected_attributes = {
303+ 'http.host' : u'localhost' ,
304+ 'http.method' : u'GET' ,
305+ 'http.path' : u'/wiki/Rabbit' ,
306+ 'http.url' : u'http://localhost/wiki/Rabbit' ,
307+ 'http.route' : u'/wiki/<entry>' ,
308+ 'http.status_code' : u'200'
309+ }
310+
311+ self .assertEqual (span .attributes , expected_attributes )
312+ assert isinstance (span .parent_span , base .NullContextManager )
288313
289314 def test__after_request_blacklist (self ):
290315 flask_trace_header = 'traceparent'
0 commit comments